Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    4

    Unanswered: Specify the DSN instead of the database path

    Is it possible in VB6 to specify the data source name of the ODBC during connection rather than identifying the database path? For example, I set up a System DSN for an Access database, with DSN "ABC". I entered the following code in VB6:
    Dim dbs As ADODB.Connection
    Set dbs = New ADODB.Connection
    dbs.Provider = "Microsoft.Jet.OLEDB.4.0"
    dbs.Properties("Data Source").Value = "C:\ABC_DB.mdb"
    dbs.Open

    What I want is to specify the data source name of "ABC" in the properties instead of the database path. My purpose is in case I change the path of my database, I just need to change it in the Control Panel->ODBC. I wouldn't have to change my code in VB anymore.

    Is this possible? How can I do this?

    Thanks!

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Check out the first example in Microsoft's ADO Q&A. It should get you started nicely!

    -PatP

  3. #3
    Join Date
    Aug 2004
    Posts
    1

    Exclamation Specify the DSN instead of the database path

    Yes, it's possible.


    • First, you should create a new "ODBC DSN" connection.
    • Then, you need to create a ADO reference in your VB6 project
    • After that, try to use the follow code:


    Dim ODBCConn As New ADODB.Connection
    ODBCConn.ConnectionString = "Provider=MSDASQL.1;Data Source=ABC"
    ODBCConn.Open

    In this example, ABC is your "ODBC DSN" connection.

    -fchaves

  4. #4
    Join Date
    Aug 2004
    Posts
    4
    Thanks for the help. I tried your suggestion and it's working. I actually tried that before but I used Microsoft.Jet.OLEDB.4.0 as the provider instead of MSDASQL.1.

Posting Permissions

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