Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2014-07-07 : 20:01:12
|
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 Beginselect * 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 |
|
BBarn
Starting Member
14 Posts |
Posted - 2014-07-08 : 08:53:51
|
If both servers are SQL you can use OPENROWSET which will be cleaner and more secure than OPENQUERY. There are tons of examples available on the topic. [url]http://msdn.microsoft.com/en-us/library/ms190312(v=sql.105).aspx[/url] |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2014-07-08 : 20:18:56
|
thank you dude. i already started using Openrowset |
|
|
|
|
|