Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Connection Issue

Status
Not open for further replies.

MacDaddyNickP

Programmer
Jun 7, 2005
22
0
0
US
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:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top