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

Switch databases on the fly (same server)

Status
Not open for further replies.
Jan 9, 2003
147
US
Hi All,

I might have to be able to do this, so I thought I'd ask if it was possible first. :)

What I (might) need to do is switch databases on the same server. The databases will have the exact same structure, but different data.

I know it can be done through the File -> Connection menu option, but I don't want the compiled version to have this available, so I'd rather my interface itself do the switching (with me specifying what databases are allowed).

It seems like this should be a fairly straightforward thing to do since it's so easy to do through the ADP interface. Any ideas?

Thanks,

Andrew
 
Hi Daniel,

Thanks for the reply. I had seen that before and it looks like it will definitly work, but I was hoping for a simpler solution I guess. Since this is only a temporary solution I think maybe it'll be easier for me to just have two copies of the interface, each pointing to a different database.

It's good to know that it is fairly easy to switch connections though.

Thanks again,
Andrew
 
Hello,

if you want to have a simple solution, just copy the part with the different connectionstring to a onclick of a button:

Code:
str_Connection = "PROVIDER=SQLOLEDB.1;" & _
    "PERSIST SECURITY INFO=FALSE;" & _
    "INITIAL CATALOG=[purple]NameOfYourfirstDB[/purple];" & _
    "DATA SOURCE=[purple]NameOfYourServer[/purple]"

CurrentProject.OpenConnection str_Connection, [purple]User, PW[/purple]

This will change the connection. But there is no errorhandling!

Regards
Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top