Wednesday, March 21, 2012

How To Connect From SQL Server Database To Another SQL Server Database

HI to all...

Im using Sql server 2005.

I have two databases.

1st database Name is : rmstime

2nd database Name is : rmsdev

Both are having Permissions(User names and passwords.)

Now i want to access a a table in rmstime from rmsdev database.

Please send me a solution.

Any help should be appreciated...

Thanx in advance.

Srinivas Kajuluri.

Assuming that you have the relevant permissions to do so, you can just access tables/sprocs/views etc with 3 part naming:

Code Snippet

SELECT * FROM rmstime.dbo.YourTable

or

EXEC rmstime.dbo.YourProc

HTH!

|||

It will work only when u have access to the database..

but i need to specify the username and password.

For Ex username and password of the databse is 'aadddd' and 'qqqwww',

know i want to know where to specify these username and passwords?

|||

use the following System stored Proc....

sp_addlinkedserver 'SERVER NAME'

|||

Ok, you didn't specify that these databases were on different servers.

In this case, you will need to add a linked server using sp_addlinkedserver and add the security using sp_addlinkedsrvlogin.

You also have the option to enable ad hoc distributed queries and then use OPENROWSET.

HTH

No comments:

Post a Comment