Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntex Error in Distributed query Expand / Collapse
Author
Message
Posted Wednesday, November 11, 2009 1:17 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 3:39 AM
Points: 158, Visits: 134
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
Post #817420
Posted Wednesday, November 11, 2009 1:35 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #817429
Posted Wednesday, November 11, 2009 1:46 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 3:39 AM
Points: 158, Visits: 134
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
Post #817435
Posted Wednesday, November 11, 2009 1:50 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 3:39 AM
Points: 158, Visits: 134
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
Post #817437
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse