If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Specify the DSN instead of the database path

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-09-04, 01:43
mijuani mijuani is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
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!
Reply With Quote
  #2 (permalink)  
Old 08-09-04, 10:59
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Check out the first example in Microsoft's ADO Q&A. It should get you started nicely!

-PatP
Reply With Quote
  #3 (permalink)  
Old 08-09-04, 18:00
fchaves fchaves is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 08-11-04, 04:15
mijuani mijuani is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On