Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Syntex Error in Distributed query


Syntex Error in Distributed query

Author
Message
Nitin Gupta - SQL DBA
Nitin Gupta - SQL DBA
SSC-Enthusiastic
SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)

Group: General Forum Members
Points: 158 Visits: 145
Hi All,

I'm try to connect multiple SQL server instances using distributed query ( OPENROWSET() ); whenever I'm executing connection string on its I'm getting syntex error on it.



set @conn= '''SQLOLEDB'', ''Server=' + @server +'; ''user id=' + @user id +'; ''Password=' +@pass'''

please correct me.

Thanks & Regards,

Nitin Gupta
SQl Server (7.0,2000,2005) - Sr. DBA
HCL Technologies, India
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
Are you building the connection dynamically inside the OpenRowset command? Or are you dynamically building an OpenRowset command? I really can't tell what you're doing from the little bit you posted.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Nitin Gupta - SQL DBA
Nitin Gupta - SQL DBA
SSC-Enthusiastic
SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)

Group: General Forum Members
Points: 158 Visits: 145
Hi, Basically I'm preparing a script to get backup details of all my servers (124 Physical Boxes in a single domain),

Steps:

1. Passing veriable name in @server and storing that script into a variable @query.
2. passind that @query into openrowset();


but when I'm seting connect string in @query like

@query = 'provider string with trusted connection' its showing syntex error on @Password

Thanks & Regards,

Nitin Gupta
SQl Server (7.0,2000,2005) - Sr. DBA
HCL Technologies, India
Nitin Gupta - SQL DBA
Nitin Gupta - SQL DBA
SSC-Enthusiastic
SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)

Group: General Forum Members
Points: 158 Visits: 145
Please find the same kind of code.

-- TO BE RUN ON SHCBBMS01 SERVER
-- For SQL 2000
set nocount on
go
declare @server varchar(256), @ctr int
declare @tbllist table (srvr varchar(256),id int identity)
insert @tbllist

select 'SHBAHYP01T' union
select 'SHBAHYP04' union
select 'SHBAINT02'


set @ctr = 1
while @ctr <= (select max(id) from @tbllist)
begin
select @server = srvr
from @tbllist
where id = @ctr
declare @conn varchar(200), @query varchar(8000), @sql varchar(8000)
set @conn= '''SQLOLEDB'', ''Server=' + @server +';Trusted_Connection=yes;'''
set @query = '''select @@SERVERNAME,name from master.sys.databases'''

select @sql = 'SELECT a.* FROM OPENROWSET('+@conn+','+@query+') AS a;'

exec( @sql )
select @ctr = @ctr + 1
end
go


In this script I want to replay trusted connection to user name & password.

as I'm new to query part please help me out.

Thanks in advance
Nitin

Thanks & Regards,

Nitin Gupta
SQl Server (7.0,2000,2005) - Sr. DBA
HCL Technologies, India
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search