| || |
Connect to MS SQL Server through ADO
I would like to connect to databases on an MS SQL server through ADO using VBScript to run a simple SELECT query. The TestComplete help shows how to do this using a DSN as the data source and I can't get that working.
Is there a way to connect to the MS SQL database directly? I can do this in ASP using the following connection string (this doesn't work in TestComplete):
"driver=sql server;server=My_Server;database=My_Database;uid=M y_Username;pwd=My_Password"
Thanks in advance for any responses and examples.
Re: Connect to MS SQL Server through ADO
Public Function fGetADOConnection()'As ADO.Connection
sFunctionName = "fGetADOConnection"
sPrompt = "The request to create the ADO connection failed."
sConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=YourUser;Password=YourPassword;" & _
"Initial Catalog=" & cInitialCatalog & ";Data Source=" & cDataSource & "\" & cInstance & ""
Set oConn = ADO.CreateConnection
.ConnectionString = sConn
If .State <> adStateOpen Then
MsgBox sPrompt, vbCritical, cE2EMsgBoxTitle & ": " & sFunctionName
I use global level variables for cInitialCatalog, cDataSource, cInstance...you may find it more useful to pass these in or hard code them. As well, you may want to handle a .State <> adStateOpen another way than just Exit Function.
[ 09-22-2004, 02:53 PM: Message edited by: kadams ]