MacDaddyNickP
Programmer
I have some code (see below) which executes a SQL Pass-Through Query which calls a stored procedure in a network SQL database. When I use the QueryDef.Connect property set to just qdf.connect = "ODBC;", the program prompts me with the expected input prompt, listing the available ODBC connections, as it is supposed to do, according to Access Help. However, when I attempt to use a connection string (.Connect = "ODBC;DATABASE=GLODSPDATA;SERVER=TIMSSQL01;UID=nick_porterfield;PWD="";DSN=NicksGLODSPDATAConnection;"), I get an error 3151, unable to connect to database. I've tried every different combination of parameters I can think of and hoped someone can help with this one.
The code is:
The code is:
Code:
Public Function TestConnection()
Dim cnnGLODSPDATA As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim strDPS_NUM, strCompany, strCity, strState, strResponse As String
Dim datSvcReqStatusDate As Date
Dim intOverall, intCommunication, intExpertise, intProfessionalism, intOnTime, intDell As Integer
Dim strSQL As String
Dim i, j, intRecCount As Integer
Dim arrRecordset
Dim qdf, qdfTestQuery As QueryDef
Dim varNPTest
On Error GoTo TestConnection_Error
'Using a QueryDef to retrieve the values in
If IsQueryDef("qdfTestQuery") = True Then
DoCmd.DeleteObject acQuery, "qdfTestQuery"
End If
Set qdf = CurrentDb.CreateQueryDef("qdfTestQuery")
'
With qdf
.Connect = "ODBC;DATABASE=GLODSPDATA;SERVER=TIMSSQL01;UID=nick_porter;PWD="";DSN=NicksGLODSPDATAConnection;"
' .Connect = "ODBC;"
.SQL = "EXECUTE NPTest @Customer_Number = 948514"
.ReturnsRecords = True
.Close
End With
DoCmd.OpenQuery "qdfTestQuery", acViewNormal, acReadOnly
Stop
DoCmd.Close acQuery, "qdfTestQuery"
Exit_Function:
Set rst = Nothing
Set cnnGLODSPDATA = Nothing
Set cmd = Nothing
Set qdf = Nothing
On Error GoTo 0
Exit Function
TestConnection_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TestConnection of Module mod_Connection"
End Function
Public Function IsQueryDef(strQueryDefName As String) As Boolean
On Error Resume Next
IsQueryDef = (CurrentDb.QueryDefs(strQueryDefName).Name = strQueryDefName)
End Function