Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi fellow qlikies.
My first post to the community! Hope you can help.
I want to pass a variable into my connectstring to be able to change the database name. Read some examples on the forum but none of them explain how to do this when you work inside the square brackets.
CONNECT TO [ Provider=SQLOLEDB.1;
Persist Security Info=True;
User ID=Sa;
Initial Catalog=DB_LIVE;
Data Source=server1;
Use Procedure for Prepare=1;
Auto Translate=True;
Packet Size=4096;
Workstation ID=ICT0231;
Use Encryption for Data=False;
Tag with column collation when possible=False] (XPassword is SCRAMBLED);
The above statement works fine. However setting ans inserting the variable won't work for me
SET DbName='DB_LIVE';
CONNECT TO [ Provider=SQLOLEDB.1;
Persist Security Info=True;
User ID=Sa;
Initial Catalog=DbName$;
Data Source=server1;
Use Procedure for Prepare=1;
Auto Translate=True;
Packet Size=4096;
Workstation ID=ICT0231;
Use Encryption for Data=False;
Tag with column collation when possible=False] (XPassword is SCRAMBLED);
What's wrong ??
Hi coolman,
this should work with: Initial Catalog=$(DbName);
- Ralf
Hi Ralph,
Thanks for stepping in. Made the change as you suggested but no luck and a timeout on connection occurs. I reckon this is because the variable is inside the [ ] brackets, because the script also doesn't mark it grey as it would normally expect.
Any suggestions?
Hi,
You could skip the Initial Database entry in the "Connect TO" and use a full qualified schema name instead.It would work with the $ expansion... DBName.Owner.Table...
I.e
SQL SELECT *
FROM $(DBName).dbo.TableName;
BR
Hans