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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing ADODC Connection String...

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
How can I set the ADODC ConnecctionString Property during runtime? I've tried it at a few different places in my code, all with errors....

Thanks,
Ray
 
Can you let me know how you are trying to do it and what kind of errors you are getting? I have been doing it without any problem.
 
Maybe I've already answered this one but the best place to run the connection string is in a Form_Load sub procedure. Here's an example. If you want to reuse this connection string in other forms, it's best to create a global variable you can call from any module even if it's private. This example will be for Access.
Form_Load()
ADODC1.ConnectionString = "Microsoft.Jet.OLEDB.4.0.,Data Source = filename"

Make sure filename specifies the full file path including the directory and the database file name with extension.


 
The error I'm getting comes up before entering the Form_Load Procedure.... (I've had it come up right at the beginning of Form_Load, (before the first line of code), or even before that. I want to be able to assign it like so:

with form1
.ADODC1.ConnectionString = "connection string"
.ADODC1.Refresh
end with

The problem is, before I get to these lines, I get an error (unnumbered) because the current connection string is invalid (I purposely misspelled it before running, since it might have to be changed during runtime). The error says someting like

"(Unknown) is not a valid path. Make sure you have spelled the pathname correctly, and that you are connected to the server on which the file resides"

How will I get around this?

Thanks,
Ray
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top