abenitez77
IS-IT--Management
I am trying to run a passthru query and get a runtime error 3146:
ODBC-- Call Failed
This is my code:
conn = "ODBC;DRIVER={SQL Server Native Client 10.0};SERVER=UKHOST04;DATABASE=COOPTRADEDISCOUNTS;TRUSTED_CONNECTION=Yes;"
sql = "Update TblGroupID Set AuditorID = 'abenit01', UpdatedDate = GetDate() From ( Select AuditorID, Min(GroupID) as MinOfGroupID From TblGroupID Group By AuditorID Having AuditorID IS NULL OR AuditorID = '') as TblGP Where TblGroupID.GroupID = TblGP.GroupID"
Call SQL_PassThrough(conn,sql)
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal sql 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 = 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
'dbs.QueryDefs.Append qdf.name
Set qdf = dbs.CreateQueryDef(QueryName, sql)
' If dbs.QueryDefs(QueryName).name = QueryName Then
' dbs.QueryDefs.Delete QueryName
' dbs.QueryDefs.Append qdf
'Else
' dbs.QueryDefs.Append qdf
'End If
End If
.Close
End With
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Function
ODBC-- Call Failed
This is my code:
conn = "ODBC;DRIVER={SQL Server Native Client 10.0};SERVER=UKHOST04;DATABASE=COOPTRADEDISCOUNTS;TRUSTED_CONNECTION=Yes;"
sql = "Update TblGroupID Set AuditorID = 'abenit01', UpdatedDate = GetDate() From ( Select AuditorID, Min(GroupID) as MinOfGroupID From TblGroupID Group By AuditorID Having AuditorID IS NULL OR AuditorID = '') as TblGP Where TblGroupID.GroupID = TblGP.GroupID"
Call SQL_PassThrough(conn,sql)
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal sql 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 = 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
'dbs.QueryDefs.Append qdf.name
Set qdf = dbs.CreateQueryDef(QueryName, sql)
' If dbs.QueryDefs(QueryName).name = QueryName Then
' dbs.QueryDefs.Delete QueryName
' dbs.QueryDefs.Append qdf
'Else
' dbs.QueryDefs.Append qdf
'End If
End If
.Close
End With
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Function