Micro Focus QTP (UFT) Forums

Full Version: DB connection string issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
Please ensure to include your code between [code] tags while asking or replying to questions. I have done this for you for this time.