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


Multiple Dymanic connection strings


Multiple Dymanic connection strings

Author
Message
Abhishek Chaturvedi
Abhishek Chaturvedi
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 283
Hi,

I am working on creating a report which should pull data from multiple instances. The instances will be passed in as parameters. I am current doing this for one instance and creating a dynamic connection to the instance using expression ="data source=" &Parameters!servername.Value &";initial catalog=master".

Now I am facing a problem in giving multiple instances names and the report should
1) Create dynamic connection to the fist instance and get the data
2) Check if there are any other instances (in the comma delimited parameters) and if there are more instance names then create the dynamic connection to the next instance and pull the data.

Any suggestions would be appreciated.
neerajstar
neerajstar
SSC-Enthusiastic
SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)

Group: General Forum Members
Points: 143 Visits: 144
Hi Try this approach, it might help you.

DECLARE @DB varchar(200)='DBName1,DBName2,DBName3......'
,@Server varchar(100)='ServerName'


CREATE TABLE #Test(COL1 varchar(20))


WHILE LEN(@DB)>0
BEGIN
DECLARE @hold varchar(100)
DECLARE @Sql VARCHAR(1000)

IF charindex(',',@DB)>0
BEGIN
SET @hold=SUBSTRING(@DB,1,charindex(',',@DB)-1)
END
ELSE
BEGIN
SET @hold=@DB
END



SET @Sql=''
SET @Sql='insert into #Test select top 10 COL1 from ['+@Server+'].['+@hold+'].dbo.TABLENAM1'

EXECUTE (@sql)


IF charindex(',',@DB)>0
BEGIN
set @DB= STUFF(@DB,1,charindex(',',@DB),'')
END
ELSE
BEGIN
SET @DB=''
END


END

SELECT * FROM #Test

DROP TABLE #Test

Thanks,
Neeraj
Abhishek Chaturvedi
Abhishek Chaturvedi
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 283
Thanks for the suggestion NeerajStar. But my question was more inclined towards the SSRS aspect. I wanted to know how can I create dynamic connections to the instances based on the parameters and display each instance data in a separate page.
I will be able to separate multiple comma delimit parameters but I am not sure how to dynamically create multiple data sources based on input parameter.
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