Change database connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 3 SQL Server databases with the same schema. I've created an Access
ADP to connect to one of them and a simple application to look at the various
table. BY manually editing the connection (by FILE | Connection and editing
the server properties) I can connect to each of the databases and run my
application.

I would like to be able to add a button to a form to allow me to select
which database to use. I've tried using CurrentProject.Connection to change
the connection string but this does not seem to work (The
CurrentProject.CloseConnection falis).
Any ideas on how to do this?
Thanks
Gary
 
Gary:

I was able to use the following code to change the database connection.

Function ChangeDatabase()
Dim sConnect As String

sConnect = CurrentProject.BaseConnectionString

sConnect = Replace(sConnect, "CurrentDatabaseName", "NewDatabaseName")

CurrentProject.CloseConnection

CurrentProject.OpenConnection (sConnect)

End Function

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have 3 SQL Server databases with the same schema. I've created an Access
ADP to connect to one of them and a simple application to look at the
various
table. BY manually editing the connection (by FILE | Connection and editing
the server properties) I can connect to each of the databases and run my
application.

I would like to be able to add a button to a form to allow me to select
which database to use. I've tried using CurrentProject.Connection to change
the connection string but this does not seem to work (The
CurrentProject.CloseConnection falis).
Any ideas on how to do this?
Thanks
Gary
 
The CloseConnection fails with an error 6008.
MSDN suggests retrying the close connection, which seems to work, except the
openconnection then fails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top