473,581 Members | 3,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple SQL Databases

I'm working on an app where I need to access a table from 2 different
databases (same MS-SQL box).

What I need is to have a SELECT string with an INNER JOIN based on these 2
tables. If they were in the same DB this would be no problem, but I can't
figure out how to get this via C#.

Any help would be greatly appreciated, thx!

-Gary
Nov 15 '05 #1
5 1832
Hi Gary,

This is a 100% SQL question :)
This is how you can access a table from another DB in the same DB-server, if
the BDs are in different servers then you need to create a link server.

select * from OTHER_DB_NAME.o wner.Table_Name

where owner is the owner of the table, by default dbo

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gary" <ga******@NOOOO SPAM.virtium.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm working on an app where I need to access a table from 2 different
databases (same MS-SQL box).

What I need is to have a SELECT string with an INNER JOIN based on these 2
tables. If they were in the same DB this would be no problem, but I can't
figure out how to get this via C#.

Any help would be greatly appreciated, thx!

-Gary

Nov 15 '05 #2
But doesn't the connection string have the "initial catalog" set to one DB?
Then how would that select call be able to access the second DB?

-Gary
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi Gary,

This is a 100% SQL question :)
This is how you can access a table from another DB in the same DB-server, if the BDs are in different servers then you need to create a link server.

select * from OTHER_DB_NAME.o wner.Table_Name

where owner is the owner of the table, by default dbo

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gary" <ga******@NOOOO SPAM.virtium.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm working on an app where I need to access a table from 2 different
databases (same MS-SQL box).

What I need is to have a SELECT string with an INNER JOIN based on these 2 tables. If they were in the same DB this would be no problem, but I can't figure out how to get this via C#.

Any help would be greatly appreciated, thx!

-Gary


Nov 15 '05 #3
As long as your 'initial catalog' database server contains the linked server entry - which can be configured with pre-defined login credentials, then you're fine.

Cheers,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 15 '05 #4
JKJ
Linked server isn't necessary in this particular case -
he states that the databases are hosted by same SQL
Server instance on the same machine (at least that is how
I understood the question). Fully qualifying the table
names should suffice.

(ansi92 sql)
SELECT [some stuff]
FROM [database].[owner].[table] a,
[database].[owner].[table] b
WHERE
a.[field] = b.[field]

Even if the databases are on two distinct machines,
linked servers aren't always necessary. Simply use the
OPENROWSET or OPENDATASOURCE function where you'd use a
linked server. But I would agree that if you are joining
these tables all the time, or executing distributed
transactions, linking the servers is probably the best
approach.

Overall, I agree with Ignacio, though, this has nothing
to do with C# ;-) Hope we helped anyway.

JKJ, MCSD.NET
-----Original Message-----
As long as your 'initial catalog' database server contains the linked server entry - which can be
configured with pre-defined login credentials, then
you're fine.
Cheers,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/.

Nov 15 '05 #5
Hi Gary,

Yes, of course you have an initial catalog, but it does not imply you
cannot access others DBs in the same server ( or in others servers using
linking ).

Anyway try it and see if it works

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gary" <ga******@NOOOO SPAM.virtium.co m> wrote in message
news:eh******** *****@TK2MSFTNG P10.phx.gbl...
But doesn't the connection string have the "initial catalog" set to one DB? Then how would that select call be able to access the second DB?

-Gary
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote in message news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi Gary,

This is a 100% SQL question :)
This is how you can access a table from another DB in the same DB-server,
if
the BDs are in different servers then you need to create a link server.

select * from OTHER_DB_NAME.o wner.Table_Name

where owner is the owner of the table, by default dbo

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gary" <ga******@NOOOO SPAM.virtium.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm working on an app where I need to access a table from 2 different
databases (same MS-SQL box).

What I need is to have a SELECT string with an INNER JOIN based on
these 2 tables. If they were in the same DB this would be no problem, but I can't figure out how to get this via C#.

Any help would be greatly appreciated, thx!

-Gary



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8691
by: rallykarro | last post by:
Hi, How do I at the best way perform select statements over multiple databases? I have a couple of databases containing the same table definitions with diffrent data. Now I want them to act as a single database giving me one answer on a select statement but the answer fetched from all my defined databases.
9
14259
by: TC | last post by:
I need to design a system which represents multiple "projects" in SQL Server. Each project has the same data model, but is independent of all others. My inclination is to use one database to store all projects. Looking at the numbers involved, however, I wonder if I would get better performance by storing each project in its own database. ...
6
2100
by: GregG | last post by:
Greetings, I've inherited a project which requires the use of multiple Access databases, each containing a dozen or so tables each. I need to perform queries which included relations and results from the contents of tables from separate databases. I've got the table adapters configured in the XSDs, connection strings in the web.config,...
1
4758
by: foneman | last post by:
I'm running Sambar 7.0, PHP 5.2 and PostgreSQL 8.2 with WinXP. I built a database that's fed with form data, and created summaries with views and PHP scripts. I cloned the database two different ways. One way used pg_dump out of the existing and pg_restore into the new, the other method was to maually execute the SQL to create all the objects....
1
7401
by: richard.crosh | last post by:
What is the IBM recommendation for the number of DB2-LUW databases per instance on AIX? With Oracle, it is one-to-one. In DB2 multiple databases can co-exist in an instance but is this recommended? What should be considered in making this decision?
0
7809
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8183
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.