Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

pass a variable into connectstring with [ ...]

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 ??

3 Replies
MVP
MVP

pass a variable into connectstring with [ ...]

Hi coolman,

this should work with: Initial Catalog=$(DbName);

- Ralf

Not applicable

pass a variable into connectstring with [ ...]

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?

Not applicable

pass a variable into connectstring with [ ...]

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

Community Browser