How to pass parameters for OPENDATASOURCE

Posted by Rapunzo on Stack Overflow See other posts from Stack Overflow or by Rapunzo
Published on 2010-05-31T14:28:06Z Indexed on 2010/05/31 14:33 UTC
Read the original article Hit count: 201

I can connect to a linked server with this:

SELECT testNo, soruTuruId, soruNo, cevap , degerlendirenTcNo, degerlendirilenTcNo FROM OPENDATASOURCE('SQLOLEDB', 'Data Source=192.168.150.42;User ID=readerUser;Password=1').akreditasyon.dbo.tblPerfCevap

But I have to pass the password as parameter. and I try like this:

SET @connectionString = 'Data Source=192.168.150.42;User ID=readerUser;Password='+@pw

SELECT testNo, soruTuruId, soruNo, cevap , degerlendirenTcNo, degerlendirilenTcNo FROM OPENDATASOURCE('SQLOLEDB', @connectionString ).akreditasyon.dbo.tblPerfCevap

and

SELECT testNo, soruTuruId, soruNo, cevap , degerlendirenTcNo, degerlendirilenTcNo FROM OPENDATASOURCE('SQLOLEDB', 'Data Source=192.168.150.42;User ID=readerUser;Password='+@pw ).akreditasyon.dbo.tblPerfCevap

but didnt work:S

does anyone have an idea?

© Stack Overflow or respective owner

Related posts about linked-server

Related posts about parameter-passing