How to connect to 2 database using one Connection at a time

Just assume,I have 2 databases configured in single sql server and each database contains one table.

Now my requirement is to join these 2 tables which are in 2 different database.

This is something like under .\sqlexpress we can see many database like Northwing,DB1 and DB2  etc....

Now i want to join 2 tables from different databases.

Here i know the SQL join query but my problem is to create the Connection string....i dont know how to create one connection string that connects to these 2 database and gives me the output.Am trying it in  VB6 ...... but am not getting...

Plz help me//////

0
Vasu
1/15/2009 2:12:34 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
889 Views

Similar Articles

[PageSpeed] 48

You don't need two connection strings. Just create one, then use DBName.dbo.TableName to refer the second DB like SELECT * FROM YourFirstDBTableName INNER JOIN YourSecondDBName.dbo.TableName ON....


"Object reference not set to an instance of an object"
0
che3358
1/15/2009 2:25:06 PM

In your connection string, connect to one of the databases (it doesn't really matter which one).

In your query, use the '3 part' naming convention, which is databasename.schemaname.tablename

Schema name is usually dbo, so a query might look like this:

Select X.Column1,
       Z.ColumnX
From   Database1.dbo.TableX As X
       Inner Join Database2.dbo.TableZ As Z
         On X.IdColumn = Z.IdColumn

Notice that I used table aliases in the from clause. This makes reading (and writing) the query a lot easier to do.

Whatever login you use for the db, you must make sure that this login has permissions to the other database too.

Make sense?


-George
0
gmmastros
1/15/2009 2:28:27 PM
Reply:

Similar Artilces:

can't connect to sql server database with same connection used in visual studio .net 2003
I have the following code that works fine in visual studio .net 2003 but not with VWD.  I have sql server 2000 developer edition installed locally and this connection works fine with visual studio.  With VWD it fails with the exception "System.Data.SqlClient.SqlException: Login failed for user 'DARRELL\ASPNET'".  It fails on the conn.Open line.   any ideas on what the issue is?Dim conn As SqlConnectionDim connstr As Stringconnstr = "Data Source=DARRELL;Initial Catalog=Event;Integrated Security=SSPI;"Dim daEvents As New SqlDataAdapter("select * from events", connstr...

Problem connecting 2 databases in the same machine. One database is running in a LAN the other in WAN, both are using NT SERVER...
Hi!!!! SQL ANYWHERE 5.5.04 Build #1867. It is possible to connect from one machine to two databases, one in a LAN another in a WAN??? I can open my WAN database alone, only. I can open my LAN database alone, only. But, If I have the WAN open and try to open the LAN db I get a connection error. If I have a LAN open and try to connect to my db in the WAN. I get a connection error. Is this possible? Do I need some special parameters??? Jos� R. Rivera Did you try the things I suggested in my reply to your Saturday mail? Regards, Thomas Sandberg, GraFu AB Jose ...

database connection problem using C# .net 2.0
 Hi,I am learning C# .net 2.0. I use below code to connect database. But, it gave me an error message as below. Please help me. string strConn = WebConfigurationManager.ConnectionStrings["SqlConnectionstring"].ConnectionString;  SqlConnection objConnect = new SqlConnection(strConn);-----------------------------------------------------Server Error in '/DOTNET2005' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your...

Using 2 connections to 2 ASE-databases using SYC adapative server enterprice driver
Help! I have a problem making 2 ASE database connections in 1 application. I use a default transaction object SQLCA to connect to 1 ASE database and a self-defined transaction object to connect to the other database. It is not possible to save such an application, because when I make a connection in Powerbuilder to both databases via an SYC Adaptive Server Enterprise driver en then save it, the tables of the not active database are not reckognized. When I make a connection via the ODBC driver it works, but other error messages occur. What is the problem with connection to 2 ASE d...

problem with Connecting to a SQL Anywhere Studio Database Using ADO.NET
I am trying to connect and read the data from the asademo.db database that is used in the document "Connecting to a SQL Anywhere Studio Database Using ADO.NET ". I am using Sql Anywhere v7.0 and MS Visual Studio .Net 2003 with C#. I can connect to the database but I get a 'Specific cas is not valid' exception when I try to run the myReader = myCommand.ExecuteReader() line in the demo course. Can anyone tell me why it is not working? I'm getting the same error using V7.0.2.1402. Did you find any solution/workaround? You need a more recent version of the A...

connect to MS SQL database using visual studio.net failed
Hi, I'm trying to connect to MS SQL 2000 using visual studio.net in window server 2003. Clicking the server explorer, connect to database icon, and selecting the provider and so on, when i click on the 'test connection', an error appear indicating : "Test connection failed because of an error in initializing provider. Device activation error. The physical name : c:\MCSDWebapps\Chapter05\vbADOsnippers\Contact.MDF may be incorrect " Note : I'm connecting to window server 2003 locally i.e I'm working on the same computer i.e server 2003. I've tried in win XP Pro and it wor...

Cannot connect to SQL Server database using ado.net after IP address has changed
Dear all, I wasn't able to connect to my SQL server 2000 database (which reside in the network in a windows 2003 server) after the IP address of the server has changed and the server is shut down, moved and re-started. I was able to connect to this server by using ADO using VB. I was able to register this server in my EM and was able to create ODBC connection. Just when using ADO.NET, I wasn't able to connect. Any ideas? Will there be any caching within ADO.NET still pointing to the old IP address? Thank you for all the help in advance. There are a lot of variable possibilites her...

Connecting to Oracle -- one time connection?
HI there, I'm new at ASP.NET 2.0 and want to connect to an oracle database.  I see how you can identifiy a data source on a datagrid but do you need to do this on every page?  Is there a way to connect to the database one time and use that connction throughout the users session? Also is it better to have the security in oracle as well if im accessing the data from there?  If I use their provided memebership tools, should i then just have a common user id/password to connect into the oracle database with?   Any help would be greatly appreciated.   A da...

how to connect sql database(vb.net) to authenticate using login n pwd
Hi there, I am new to programming. Can any one please tell me how to connect to sqldatabase through vb.net. I must use login n password to authenticate the user.. if authenticated i must return true  Please help!! The video How Do I: Set Up the SQL Membership Provider should show you everything you need."Peace is Every Step." -Thich Nhat Hanh Hi there,  Thanks for ur reply. I am using a webservice where i get login n password from client request. I the link u hav provided show how to use login details in asp.net. And they hav used connection string in web co...

Oracle database connection using Visual Studio 2005 and .Net 2.0 framework
My connection string is in my web config file, generated when I added a sql data source.  I can go under tools and connect to database and compare the connection string there to the one in web config and they are the same but when I try to view my page which contains a gridview I get a database connection error saying  "Keyword not supported: 'unicode'."  When I remove the unicode=true parameter from the connection string then I get an error message about trying to connect to sql server.  Could someone please give me a clue on how to go about solvin...

PB 10.2.0 Connect SQL Server Using ADO.NET Provider
I have a problem with connection to SQL Server database using ADO.NET after upgrading to PB10.2.0 build 8011 runtime on the client machine. But it worked fine in version 10.0.1 build 6044 . Anyone can help me to figure ot that problem? TIA. John Ho. Can you try to provide details of the problem? <John Ho> wrote in message news:427aeaa1.7f95.1681692777@sybase.com... >I have a problem with connection to SQL Server database > using ADO.NET after upgrading to PB10.2.0 build 8011 runtime > on the client machine. But it worked fine in version 10.0.1 > build 604...

Connect to 2 databases, but no use 2 phase commit
I have a component submitted to the thread manager a service component that wakes and sleeps. When it wakes, it should connect to multiple connection caches, gather some statistics, update a value and then disconnect and move to the next connection cache. It's giving me errors about 2-phase commit. I understand why I get the error. If I don't care about 2 phase commit (if one update fails, the other can commit, data integrity is no real concern here since the update is basically just "I was here" - not mission critical) can I do this with one component call, or...

Why do I have to allow Firefox (2.0.0.7) to connect with one or more sites before I can connect with my Earthlink dial-up connection.
Name: George Ginsburg Email: ginsburgattiacdotnet Product: Firefox Summary: Why do I have to allow Firefox (2.0.0.7) to connect with one or more sites before I can connect with my Earthlink dial-up connection. Comments: When I simply bring up Firefox, I get the following or similar messages which come from my security monitor on outgoing message requests: first: "firefox-bin wants to connect to static-fxfeeds.nslb.sj.mozilla.com on TCP port 80 (http)," second: (typical) firefox-bin wants to connect to 130.94.77.118 on TCP port 443 (https)," third type: paraphr...

Connecting to Sql database and retrieving one row of data from database
Hi Guys.I am trying to connect to a Sql Database in my application through an object of SqlConnection class,then trying to read data one row at a time through DataRow class and then displaying each column(there are total 3 columns in a row) in three textboxes.Can anyone tell me the code to do so? Hi, Reffer this link for connecting with sql server and also with Insert update Delete and select statements http://www.aspsnippets.com/post/2009/02/09/Parameterized-Queries-ADONet.aspx   Best Regardslife is name of learning!Mark as an answer if it helps...

Web resources about - How to connect to 2 database using one Connection at a time - asp.net.sql-datasource

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video - iMediaConnection.com
If you send more email, you might make more money. Then again, you might destroy your reputation and revenue stream. Here's how to know what ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

MOTHER’S DAY: Facebook Examines Connections Between Moms, Kids
With Mother’s Day on the calendar this coming Sunday, Facebook examined the relationships between mothers and their children on the social network, ...

The Direct Connection
... And the people reading my words respond back to me with words of their own. The technology that allows this is powerful but this direct connection ...

Is There A Connection Between Patrick Murphy's Over-The-Top Corruption And His Campaign Emails?
The DCCC may be stupid or even very stupid (as well as utterly incompetent) but their e-mail strategy is very well-planned out. Their overarching ...

CNN: Investigators Find ISIS Connection In San Bernardino Shooting
As the San Bernardino attack was happening, the female shooter, Tashfeen Malik posted on Facebook, pledging allegiance to ISIS leader Abu Bakr ...

Connection And Collaboration In the Cloud
Forbes technology editor Bruce Upbin deconstructs the cloud and maps its potential to your life.

Man wanted in connection to Waco biker shooting arrested in Louisiana
A man wanted in the deadly shootout involving rival motorcycle gangs earlier this year in Texas was arrested in northwest Louisiana on Wednesday, ...

Kidney Donor Connection Made After Misplaced Craigslist Ad
Man whose wife died of kidney failure becoming a donor after seeing misplaced Craigslist ad

Resources last updated: 12/6/2015 5:36:16 PM