Results 1 to 2 of 2

Thread: How TO Create/Delete Microsoft Access Driver (*.Mdb) DSN at RUNTIME

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    hyderabad
    Posts
    5

    Question

    Please Send Me Reply
    chandu

  2. #2
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Thumbs up

    Declare the following in a module :
    Code:
    Public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
                                                    (ByVal hwndParent As Long, _
                                                     ByVal fRequest As Long, _
                                                     ByVal lpszDriver As String, _
                                                     ByVal lpszAttributes As String) As Long
                                                        
    
    ' SQLConfigDataSource consts
    Public Const ODBC_ADD_DSN = 1          ' Add user data source.
    Public Const ODBC_CONFIG_DSN = 2       ' Configure user data source.
    Public Const ODBC_REMOVE_DSN = 3       ' Remove user data source.
    Public Const ODBC_ADD_SYS_DSN = 4      ' Add system data source
    Public Const ODBC_CONFIG_SYS_DSN = 5   ' Configure system data source
    Public Const ODBC_REMOVE_SYS_DSN = 6   ' Remove system data source
    Use the declared API with the following :
    Code:
    ' Set to one of SQLConfigDataSource consts
    intAction = 1
    
    ' Set the DSN Name
    strDSN = "Some_DSN_Name"
    
    ' Set the DB Path
    strDBPath = "c:\temp\database.mdb"
    
    ' Set the Driver info
    strDriver = "Microsoft Access Driver (*.mdb)" & Chr(0)
    
    ' Set the Attributes
    strAttributes = "DSN=" & strDSNName & Chr(0)
    strAttributes = strAttributes & "Uid=" & Chr(0) & "pwd=" & Chr(0)
    strAttributes = strAttributes & "DBQ=" & strDBPath & Chr(0)
    
    lngRetVal = SQLConfigDataSource(0, intAction, strDriver, strAttributes)
    Hope this helps.

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