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 Westi 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 Data Control ConnectionString Property At Runtime

Status
Not open for further replies.

jerjim

Programmer
Jan 4, 2001
85
PH
I have at lease one ADO data control on several VB forms.
Their ConnectionString property is set to the ff. value:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\ Security Info=False

Please note that the database H3.mdb is on drive C.

For various reasons when I install my program on another computer,
the database has to be located on drive D instead of Drive C

Thus in the above connection string I have to replace C: with D:
and set at runtime the ConnectionString property of all my ADO Data Controls on all forms

With adoDataControl
.ConnectionString = sNewConnectionString
.Refresh
end with

The variable sNewConnectionString has the value:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub\ Security Info=False

All that has changed is the drive letter.

The problem now is when the Refresh method is called,
VB flashes an error saying it could not find the file on Drive C:
But when I checked the value of the ConnectionString property,
it already has the value of the variable sNewConnectionString.

Is there anything else I should do?
 
Maybe you got your old connectionstring pointing to the C-drive in the design-time property Connectionstring?

Herman :-Q
 
That's precisely why I am setting the connection string property at run time. At design time, this property was pointing to a folder in drive C. At run time I want to set it to point to a folder in drive D.
 
You misunderstood me. What I meant is maybe the connectionstring is still in the designtime property pointing to C:. But I tested it, that doesn't cause the problem.
Did you insert an errorhandler in the code, so that you're sure this string is causing the problem? Did you debug the connectionstring at runtime? Is this the only datacontrol or can it be another which has the wrong value?

Questions, questions, questions

Herman :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top