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!

Changing ADODC Connection String

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
0
0
US
How can I set the ADODC ConnectionString Property within code during runtime? I've put it in a few different places in code, all with errors...

Thanks in advance,
Ray
 
If you are coding the connection (not in the ADODC Object), the easiest (and the recommended in some books) way to do is making a connection "in fly" and closing and opening every time you need to:

Dim cn As New ADODB.Connection

Private Sub cmdConnect ()
If cn.State <> adStateClosed Then cn.Close
cn.Open &quot;....(string connection&quot;

End Sub
This will work every time the user press the Connect button.

If you are using an ADODC Object you only have to insert the connection string on the ADODC1.ConnectionString Property and refresh it
I hope this will help you
 
I'm using the ADODC Object.
setting it by ADODC1.ConnectionString = &quot;connection string&quot; doesn't work, because before I even get to this line it gives me an error (apparently untrappable, from the ADODC) about '&quot;unknown&quot; is not a valid path name...'. (I purposely made the connection string invalid until I set it for testing purposes) In other words, it's not letting me set the ConnectionString during run-time because I always get an error from it being invalid before I can set it...

Any help would be appreciated...
Thanks,
Ray
 
I tried to insert the connection string into ADODC1.ConnectionString Property then refresh it. I replace the old one with the new one.
It works.

Perhaps there's something else in your code that generate that error.
 
Did your old connection string contain an invalid pathname? I want the application to be prepared for that situation; it seems to be the only thing causing the error, but I'll check for other things... Thanks....
 
As oneshadow says, you can change the ConnectionString at run-time. The way I've used this is by putting in any valid set of connection properties at design-time, and changing the properties at run-time to the ones I wanted. I found it best to confirm the ConnectionType property at run-time aswell.

Craig
 
Hi,

&quot;about '&quot;unknown&quot; is not a valid path name...'&quot;
Basically, ADO is not finding your database. There could be a number of reasons for this, like a malformed string, or that the database has been moved.

Are you using a DSN or DSN-less connection, if DSN-Less, are you specifying the full path?

There are a lot of things that could be wrong, but I hope this points you in the right direction.

Best of luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top