我想动态创建ODBC,不知如何实现,请教大家:
我的要求:
1、首先检查有没有:“test”的ODBC连接(连接SQL Server 2000)
2、没有的话就创建用户名为:Usr,密码为Pw的ODBC连接“test”
谢谢!!!

解决方案 »

  1.   

    Dim strConn
    strConn = "PROVIDER=MSDASQL;driver={SQL Server};Pwd=Pw;Persist Security Info=True;UID=Usr;Initial Catalog=test;database=test;server=127.0.0.1"'建立数据库连接
    Dim ObjConn
    if ObjConn.State<>1 then 
       set ObjConn = server.CreateObject("adodb.connection")
       ObjConn.Open strConn
    end if dim ARst
    set ARst=Server.CreateObject("ADODB.Recordset")ACnn.Open sCnn
      

  2.   

    dim ARst
    set ARst=Server.CreateObject("ADODB.Recordset")ACnn.Open sCnn
    这些不要,不好意思
      

  3.   

    不行啊,不能动态生成ODBC的DNS啊!
      

  4.   

    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
    提示:如能连上则说明数据源已经创建,如连不上就用上面的程序创建数据源