Single connection string to access 2 databases on the same sqlserver

B

Bill nguyen

Is there a way to access 2 databases simultaneously using a single
connection string?
I'm working on a VB.NET application and using 2 different connection strings
to access each database..

server: SQLSERVER
databases:
gasstations
customers


Thanks

Bill
 
A

Al Reid

Sure. You need to specify both the database and the table for the tables that not in the database specified in the connection
string. Assuming you have the "gasstations" database specified in the connection string you can access the tables in the
"customers" database (if you proper security access to it) as follows:

SELECT * FROM customers.dbo.table_name WHERE ...

or

SELECT * FROM customers..table_name WHERE ...

I hope this helps.
 
B

Bill Nguyen

Thank you both, Al & Cor.

Bill

Al Reid said:
Sure. You need to specify both the database and the table for the tables
that not in the database specified in the connection
string. Assuming you have the "gasstations" database specified in the
connection string you can access the tables in the
"customers" database (if you proper security access to it) as follows:

SELECT * FROM customers.dbo.table_name WHERE ...

or

SELECT * FROM customers..table_name WHERE ...

I hope this helps.

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you
know
for sure that just ain't so." --- Mark Twain
 

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

Top