创建一个DSN,代码如下
    Dim en As rdoEnvironment
    Dim cnTest As rdoConnection
    Dim strAttribs As String
    '建造关键字字符串。
    strAttribs = "Description=" _
     & "SQL Server on server SEQUEL" _
     & Chr$(13) & "OemToAnsi=No" _
     & Chr$(13) & "SERVER=(local)" _
     & Chr$(13) & "Network=DBNMPNTW" _
     & Chr$(13) & "Database=taxbox" _
     & Chr$(13) & "Address=\\SEQUEL\PIPE\SQL\QUERY"
    '建立新的注册的 DSN。
    rdoEngine.rdoRegisterDataSource "taxbox", _
     "SQL Server", True, strAttribs
     Unload Me
     Exit Sub
    '打开数据库。
    Set en = rdoEngine.rdoEnvironments(0)
   
    Set cnTest = en.OpenConnection( _
     dsname:="taxbox", _
     Prompt:=rdDriverNoPrompt, _
     Connect:="UID=sa;PWD=;")问题在于,创建的DSN在“SQL如何验证登录ID的真伪”时,默认为使用用户输入的默认ID和密码验证,我想改成使用网络登录ID和WINDOWS NT验证,应该怎么做?

解决方案 »

  1.   

    你可以通过系统带的ODBC手工建立一个,然后看看其在注册表中是怎么写的,就可以了~~~~
      

  2.   

    Public Function Create_Commail_DataSource(DsName As String, PathStr As String) As Boolean    '创建数据源
      
      Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String
      Dim rc As Integer          'ODBC 函 数 的 返 回 码
      Dim henv As Long           'ODBC 环 境 句 柄
      
        rc = SQLAllocEnv(henv)   ' 获 取ODBC 环 境 句 柄
        
        strDriver = "Microsoft Access Driver (*.mdb)"
        strAttributes = "SERVER=Local" & Chr$(0)
        strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
        strAttributes = strAttributes & "DSN=" & DsName & Chr$(0)
        strAttributes = strAttributes & "DBQ=" & PathStr & Chr$(0)
        strAttributes = strAttributes & "UID=" & Chr$(0)
        strAttributes = strAttributes & "PWD=" & Chr$(0)
        intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
        strDriver, strAttributes)
        If intRet Then
           Create_Commail_DataSource = True
        Else
           Create_Commail_DataSource = False
        End IfEnd Function
      

  3.   

    原来是要加上Trusted_Connection=Yes
    thank you,射天狼
      

  4.   

    myhgyp(也许是这样的,信不信由你)兄的方法我没试,不知道如何了