ODBC 里FILEDSN可以正常连接,但在程序里不用ODBC直接用语句连接不上,
是什么原因

解决方案 »

  1.   

    '连接示例:
    dim conn as new adodb.connection
    With conn
        If .State = adStateOpen Then .Close
        .ConnectionString = "driver=SQL Server;server=计算机名或IP地址;uid=SA;pwd=SA的密码;database=数据库名"
        .CommandTimeout = 0
        .Open
    End With
      

  2.   

    CNN.OPEN  "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=" & _
             UserID & ";Initial Catalog=" & Database & ";Data Source=" & _
             Server & ";Password=" & Password & ";"
      

  3.   

    MyCnn.ConnectionString = "Provider=SQLOLEDB.1;Password=1216;Persist Security Info=True;User ID=sa;Initial Catalog=地址库补充;Data Source=GOLDEN-WANGHUI  
    这样写可以把经常变的initial catalog和data source 写在文本里随时改,比较方便
      

  4.   

    Set cn = New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库地址;Persist Security Info=False"
        sql = "select*from 表1"
        Set rs = New ADODB.Recordset
        rs.Open sql, cn, adOpenStatic, adLockOptimistic
      

  5.   

    Set CN = New ADODB.Connection
    cn.open "DRIVER={SQL SERVER};SERVER=server;UID=sa;pwd=yy;APP={Microsoft Data Access Components};DATABASE=xx"
    出错
    Set CN = New ADODB.Connection
    cn.open "DRIVER=SQL SERVER;SERVER=server;UID=sa;pwd=yy;APP={Microsoft Data Access Components};DATABASE=xx"
    也不行
    Set CN = New ADODB.Connection
    cn.open "Provider=sqloledb;Server=SERVER;Database=XX;Uid=sa;pwd=YY"
    没用