Micro Focus QTP (UFT) Forums
DB connection string issue - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: DB connection string issue (/Thread-DB-connection-string-issue)



DB connection string issue - jackmartins - 07-04-2013

I’ve been trying to figure out how to write the connection string (for a database which uses named instance) in QTP test scripts without success.

In a different computer where default named instance is used then the following works
Code:
cnt.ConnectionString= "Driver={SQL Server};Integrated Security=SSPI;Initial Catalog=cccccc;[b]Data Source=.[/b];UID=uuuuuu;PWD=pppppp;Trusted_connection=True"

but in a computer where instance name is used, I tried the followings:

Code:
cnt.ConnectionString= "Driver={SQL Server};Integrated Security=SSPI;Initial Catalog=cccccc;[b]Data Source=.\instance_name[/b];UID=uuuuuu;PWD=pppppp;Trusted_connection=True"
cnt.ConnectionString= "Driver={SQL Server};Integrated Security=SSPI;Initial Catalog=cccccc;[b]Data Source=computer_name\instance_name[/b];UID=uuuuuu;PWD=pppppp;Trusted_connection=True"
cnt.ConnectionString= "Driver={SQL Server};Integrated Security=SSPI;Initial Catalog=cccccc;[b]Data Source=computer_ipaddr\instance_name[/b];UID=uuuuuu;PWD=pppppp;Trusted_connection=True"
but nothing works!!!

I’m wondering if anyone here can show me how to; I’d really appreciate your help.
Thanks in advance.


RE: DB connection string issue - SteveS - 07-04-2013

This is what I use and it works for me:

Code:
objDB.ConnectionString = "Provider=SQLOLEDB; Data Source=MACHINENAME\INSTANCENAME; Initial Catalog=DATABASENAME; Integrated Security=SSPI; Trusted_Connection=Yes"
objDB.Open

This assumes Windows Authentication so you do not need the username and password. If you need SQL authentication then you need to drop the Integrated Security=SSPI; Trusted_Connection=Yes" and put in your username and password.


RE: DB connection string issue - Staff - 07-05-2013

Please ensure to include your code between [code] tags while asking or replying to questions. I have done this for you for this time.