Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help needed in sqlservers connection Expand / Collapse
Author
Message
Posted Monday, July 7, 2014 5:05 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 3:54 PM
Points: 98, Visits: 336
Hi,

I have two database in different servers and i need to access one db object in another db. for ex, server1 (db1) and server2(db2(tableA,tableB) )

I will be writing a stored procedure in in db1 and i wanted to access the TableA's data of db2. i am aware of using the linked server. but i am, looking for alternate for linked server because i need to pass credentials at runtime to connect the server and access the objects.

Ex:

Create Procedure Test(@server varchar(50),@username varchar(20), @pwd varchar(20))

as

Begin

select * from server2.db2.tableA;

End

the alternate i found is OpenQuery. not sure how should i accomplish using openquery and am not sure about the drawback of using this. please suggest me the best way to achieve this and if possible show me some sample.

Thanks in advance
Post #1590156
Posted Monday, July 7, 2014 6:17 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 2:26 PM
Points: 5,466, Visits: 7,647
KGJ-Dev (7/7/2014)
I will be writing a stored procedure in in db1 and i wanted to access the TableA's data of db2. i am aware of using the linked server. but i am, looking for alternate for linked server because i need to pass credentials at runtime to connect the server and access the objects.


I'd still use the Linked Server. If you're looking to have the linkage impersonate someone, you can do that during linked server setup if it's generic. If you want to setup as a specific user so you can control your impersonation, use the EXECUTE AS clause on a procedure.

You don't want to set it up in a way where you're going to pass in a name/password for the other server on every call. It's, at best, painful.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1590162
Posted Monday, July 7, 2014 6:58 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 3:54 PM
Points: 98, Visits: 336
Hi Craig,

Thanks for your reply. I will not be using this mechanism often. also i am informed to use non linked server that's why i started to do the research. Finally i tried with open Rowset and i am able to acheive with concern. My concern is , i tried in my local database and for just returning 4 rows it took 00:00:01 by means 1 second which is bad. because my table has only 4 rows. so to return 4 rows it should not take 1 second. any suggestion please

My code:

declare  @sql nvarchar(max)

select @sql = 'select a.* from openrowset(''MSDASQL'', ''Driver={SQL SERVER}; Server=testserver;UID=sa; PWD=loginpwd;'', ''select * from [sample].dbo.Company'') as a'

exec sp_executeSQL @sql

Post #1590170
Posted Tuesday, July 8, 2014 9:40 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 3:54 PM
Points: 98, Visits: 336
can anyone please help me in this regard
Post #1590417
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse