SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

sqllover
Constraint Violating Yak Guru

India
334 Posts

Posted - 07/07/2014 :  20:01:12  Show Profile  Reply with Quote
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

BBarn
Starting Member

USA
11 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.

http://msdn.microsoft.com/en-us/library/ms190312 v=sql.105 .aspx
Go to Top of Page

sqllover
Constraint Violating Yak Guru

India
334 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000