Sql – Unable to connect to SQL2005 using VBScript

sql serversql-server-2005vbscript

I have the following VBScript, which is supposed to connect to a SQL Server 2005 database. But, my connection is failing. Why?

Set dbConnection = CreateObject("ADODB.Connection")

dbConnString = "Provider=SQLOLEDB.1;Data Source=srv\test1;" & _
               "Initial Catalog=tset_DB;user id ='abc';password='abc'"

'Open the connection
dbConnection.Open dbConnString

Best Answer

You don't need quotations around your username and password. Try this:

Set dbConnection = CreateObject("ADODB.Connection")

dbConnString = "Provider=SQLOLEDB.1;Data Source=srv\test1;" & _
               "Initial Catalog=test_DB;user id =abc;password=abc"

'Open the connection
dbConnection.Open dbConnString

Also, your Initial Catalog was set to tset_DB, when I'm guessing it should be test_DB.

ConnectionStrings.com is a huge help for ensuring that your connection strings are valid.