Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help Needed in sqlserver access
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

338 Posts

Posted - 07/07/2014 :  20:01:12  Show Profile  Reply with Quote

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.


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



select * from  server2.db2.tableA;


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

Starting Member

14 Posts

Posted - 07/08/2014 :  08:53:51  Show Profile  Reply with Quote
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. v=sql.105 .aspx
Go to Top of Page

Constraint Violating Yak Guru

338 Posts

Posted - 07/08/2014 :  20:18:56  Show Profile  Reply with Quote
thank you dude. i already started using Openrowset
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000