Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the ADO database path at run time

Status
Not open for further replies.

Lynus

Technical User
Apr 12, 2003
69
0
0

Please help. I have an application where I want to set the ADO database paths at run time. I have the ADO objects on the app with no connection string. Then as the form loads I try to set the connection string and recorset. The database will be with the program executable when it installs.
Here is the code

Private Sub Form_Load()
Dim mypath As String
mypath = App.Path
Dim dbconnect As String

dbconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + mypath + "\BugDB.mdb;Persist Security Info=False"
Adodc1.ConnectionString = dbconnect
Adodc1.RecordSource = "Bugs"

When I run the app I get an error : "Data source name not found and no default driver specified" I cant figure out what I am doing wrong. Please help!
 
First of all:
You should change the concatenation of strings from "+" to "&". It's probably not the cause of the problem, but it is considered best practise and it could create problems elsewhere in string concatenations (VB might try to cast the strings to be concatenated to variables of a numeric type and perform simple math.

What might be the problem is that there's a space between ;Data Source= and the path to the datasource.


Greetings,
Rick
 
A few questions come to mind:

dbconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + mypath + "\BugDB.mdb;Persist Security Info=False"
Adodc1.ConnectionString = dbconnect
Adodc1.RecordSource = "Bugs"


1. Is 'Bugs' the name of a table in the db

2. Where are you setting Adodc1.CommandType - are you sure it's set to adCmdTable

3. Have you tried putting a [tt]debug.print dbconnect[/tt] statement immediately after you build the dbconnect variable

4. If so, stick the path & filename from there into the immediate window and do a Dir on it - do you actually get the db [tt]? dir ("file&pathfromdbconnect")[/tt]

5. I would use '&' not '+' to concatenate strings


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 

"I have the ADO objects on the app with no connection string"

Have you also removed the RecordSource from the properties window?
 
Hi Guys. First of all thank you very much for your responses they were very quick. This was my first post to a programming BB and I am very surprised by how quick the responses came in.You people ROCK!

I changed the "+" to "&". Thanks for the tip.

I also found my problem. I cleaned out the connection string but forgot yo change the recordsource. The object was still pointing to a table. Which logically makes sense.

So I fixed it. But thanks for the speedy replys and I am sure you will see more of me around.

~Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top