abenitez77
IS-IT--Management
I am trying to call a stored procedure with a passthru query but it is not working for me. I get Run-time error '3146':
ODBC --call failed.
strconn = "ODBC;DRIVER={SQL Server Native Client 10.0};SERVER=UKHOST04;DATABASE=CoOpClaimConceptReferenceTables;TRUSTED_CONNECTION=Yes;"
mysproc = "exec dbo.RecalculateScan 110300032"
Call SQL_PassThrough(strconn, mysql)
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal strsql As String, _
Optional ByVal QueryName As String)
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
dbs.QueryTimeout = 1800
Set qdf = dbs.CreateQueryDef
With qdf
.name = QueryName
.Connect = ConnectionString
sql = strsql
.sql = sql
.ODBCTimeout = 1800
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else 'A query of QueryName must be manually created first time or this will error out.
For Each qdf In dbs.QueryDefs
If qdf.name = QueryName Then
dbs.QueryDefs.Delete QueryName
Exit For
End If
Next
Set qdf = dbs.CreateQueryDef(QueryName, sql)
End If
.Close
End With
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Function
ODBC --call failed.
strconn = "ODBC;DRIVER={SQL Server Native Client 10.0};SERVER=UKHOST04;DATABASE=CoOpClaimConceptReferenceTables;TRUSTED_CONNECTION=Yes;"
mysproc = "exec dbo.RecalculateScan 110300032"
Call SQL_PassThrough(strconn, mysql)
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal strsql As String, _
Optional ByVal QueryName As String)
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
dbs.QueryTimeout = 1800
Set qdf = dbs.CreateQueryDef
With qdf
.name = QueryName
.Connect = ConnectionString
sql = strsql
.sql = sql
.ODBCTimeout = 1800
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else 'A query of QueryName must be manually created first time or this will error out.
For Each qdf In dbs.QueryDefs
If qdf.name = QueryName Then
dbs.QueryDefs.Delete QueryName
Exit For
End If
Next
Set qdf = dbs.CreateQueryDef(QueryName, sql)
End If
.Close
End With
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Function