CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 1999
    Posts
    1

    How to set up an ODBC Conection

    I would like to obtain some code to automatic set up an ODBC conection by calling the interface API of windows.


  2. #2
    Join Date
    Jan 2000
    Posts
    16

    Re: How to set up an ODBC Conection

    Try this code. It will set up a user odbc driver for an sql database.


    Dim rc as Long

    'Allocate environment for the driver
    rc = SQLAllocEnv(hwnd)
    If rc <> 0 then
    MsgBox "Unable to allocate environment."
    End
    End If


    rc = SQLConfigDataSource(0, 1, "SQL Server", _
    "DSN=" & Driver & Chr(0) & _
    "Server=" & IPAddress & Chr(0) & _
    "Database=" & Chr(0) & _
    "UseProcForPrepare=Yes" & Chr(0) & _
    "Description=" & Chr(0) & Chr(0))





  3. #3
    Join Date
    Jan 2000
    Posts
    16

    Re: How to set up an ODBC Conection

    Oops
    Don't forget to put this in a module to declare
    the dll.


    public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (byval HM as Integer, byval Rq as Integer, byval Driver as string, byval Connect as string) as Integer







  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: How to set up an ODBC Conection

    You don't need to call SQLAllocConv in order to call SQLConfigDataSource.
    If you call it, you should also call SQLFreeEnv, and, the return value is not a return code, but a HENV - an environment handle.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: How to set up an ODBC Conection

    you can use the RegisterDatabase method of the DAO object model, or use the "ODBC Driver and Data Source Name functions" Typelib that comes with VB 6's APE (Application Performance Explorer)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured