469,608 Members | 1,785 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

Single connection string to access 2 databases on the same sqlserver

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
Dec 2 '05 #1
3 1592
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

"Bill nguyen" <bi*****************@jaco.com> wrote in message news:ub****************@TK2MSFTNGP14.phx.gbl...
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

Dec 2 '05 #2
Bill,

In addition to Al, I use the Use statement in those cases.

http://msdn.microsoft.com/library/en...ua-uz_47c5.asp

I hope this helps,

Cor

"Bill nguyen" <bi*****************@jaco.com> schreef in bericht
news:ub****************@TK2MSFTNGP14.phx.gbl...
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

Dec 2 '05 #3
Thank you both, Al & Cor.

Bill

"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:OD**************@TK2MSFTNGP14.phx.gbl...
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

"Bill nguyen" <bi*****************@jaco.com> wrote in message
news:ub****************@TK2MSFTNGP14.phx.gbl...
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


Dec 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.