Page 1 of 1

Use 2 bases on same server

Posted: Tue 05 Nov 2013 14:17
by Mario9
Hi

I have a problem with my connection on SqlServer

I will like to use 2 tables on 2 bases different on the same serveur Mssql.

Do you have example to connect 2 bases on the same server and after connection use 2 tables

One Base is easy. How do you do for the second base to connect.

Excuse my English...

Mario

Re: Use 2 bases on same server

Posted: Wed 06 Nov 2013 09:34
by AlexP
hello,

To access tables from different databases using one connection, you should explicitly specify database names before table names, for example:

Code: Select all

SELECT * FROM Northwind.dbo.Products;
Or use 'Use' to specify the database you want to work with:

Code: Select all

USE Northwind;
SELECT * FROM dbo.Products;
P.S. The user, under which you are logging in the server, must have proper rights for the used databases.

Re: Use 2 bases on same server

Posted: Wed 06 Nov 2013 15:10
by Mario9
Tank you

I have one question again

My application use a MsTable and Msdatasource for my first base no problem my connection
use Msconnection1 to connect my server and base How to connect the second base with MsTable

Base one
1= MsTable1.tablename:='Nom' because Table1 is connect on first base

Base two
2= MsTable2.tablename:='adresse' or MsTable2.tablename:='Base2.adresse.dbo'

Thank you again

Mario

Re: Use 2 bases on same server

Posted: Thu 07 Nov 2013 09:09
by AndreyZ
Here is a code example:

Code: Select all

MSTable1.TableName := 'DatabaseName1.SchemaName1.TableName1';
MSTable2.TableName := 'DatabaseName2.SchemaName2.TableName2';

Re: Use 2 bases on same server

Posted: Thu 07 Nov 2013 15:31
by Mario9
Thank you

I appreciate your support

Your explains was very good.My test is ok.

Thank again

Mario

Re: Use 2 bases on same server

Posted: Thu 07 Nov 2013 15:48
by AndreyZ
I am glad I could help. If any other questions come up, please contact us.