ukaquanaut
Registered User.
- Local time
- Today, 11:22
- Joined
- Feb 8, 2012
- Messages
- 33
Hi Guys
My Access App connects to an SQL Server to collect product data that we print 2D matrix barcodes for. In general that all works really well. However, currently if the ODBC link is down for any reason the App Errors out and crashes. I have put trapping code in now to check the Internet is up, and the SQL Server is available with a ping and lastly I want to just check and trap errors with the OBDC link.
I have a bit of VBA that connect through the ODBC, with a connection string that works from the table it fetches for the product data, but I'd like to perform some action on the SQL Db to trigger any issues and trap them.
I don't really know how to do this but I've cobbled together the VBA below.
Public Function fnTestODBC(TestConnectionString As String) As Boolean
On Error GoTo ODBCTestErrHandler
Dim qdf As DAO.QueryDef
Dim strQuery, strSQL As String
Set qdf = CurrentDb.CreateQueryDef(strQuery)
strSQL = "SELECT TOP 1 NAME FROM sysobjects"
With qdf
.Connect = TestConnectionString
.Execute strSQL
.Close
End With
fnTestODBC = True
Exit Function
ODBCExitProcedure:
Set qdf = Nothing
Exit Function
ODBCTestErrHandler:
Select Case Err.Number
Case 3376, 3010, 7874, 2059, 7873
MsgBox "DEBUG: (2210) " & conConnectivityQry & vbCrLf & Err.DESCRIPTION, vbInformation, "Error"
fnTestODBC = False
Resume Next
Case Else
MsgBox "DEBUG: (2230) " & conConnectivityQry & vbCrLf & Err.DESCRIPTION, vbInformation, "Error"
fnTestODBC = False
GoTo ODBCExitProcedure
End Select
End Function
The problem is the line with .Execute strSQL which does not appear to work I get a data type conversion error. The theory as I understand it making an ODBC connection doesn't actually prove anything, you have to execute some query and this "SELECT TOP 1 NAME FROM sysobjects" was offered by web peeps on other sites, but not being as SQL Server guru, I'm taking it a face value.
I wonder if anyone could point me in the right direction please? Thanks in advance
Regards
Jerry
My Access App connects to an SQL Server to collect product data that we print 2D matrix barcodes for. In general that all works really well. However, currently if the ODBC link is down for any reason the App Errors out and crashes. I have put trapping code in now to check the Internet is up, and the SQL Server is available with a ping and lastly I want to just check and trap errors with the OBDC link.
I have a bit of VBA that connect through the ODBC, with a connection string that works from the table it fetches for the product data, but I'd like to perform some action on the SQL Db to trigger any issues and trap them.
I don't really know how to do this but I've cobbled together the VBA below.
Public Function fnTestODBC(TestConnectionString As String) As Boolean
On Error GoTo ODBCTestErrHandler
Dim qdf As DAO.QueryDef
Dim strQuery, strSQL As String
Set qdf = CurrentDb.CreateQueryDef(strQuery)
strSQL = "SELECT TOP 1 NAME FROM sysobjects"
With qdf
.Connect = TestConnectionString
.Execute strSQL
.Close
End With
fnTestODBC = True
Exit Function
ODBCExitProcedure:
Set qdf = Nothing
Exit Function
ODBCTestErrHandler:
Select Case Err.Number
Case 3376, 3010, 7874, 2059, 7873
MsgBox "DEBUG: (2210) " & conConnectivityQry & vbCrLf & Err.DESCRIPTION, vbInformation, "Error"
fnTestODBC = False
Resume Next
Case Else
MsgBox "DEBUG: (2230) " & conConnectivityQry & vbCrLf & Err.DESCRIPTION, vbInformation, "Error"
fnTestODBC = False
GoTo ODBCExitProcedure
End Select
End Function
The problem is the line with .Execute strSQL which does not appear to work I get a data type conversion error. The theory as I understand it making an ODBC connection doesn't actually prove anything, you have to execute some query and this "SELECT TOP 1 NAME FROM sysobjects" was offered by web peeps on other sites, but not being as SQL Server guru, I'm taking it a face value.
I wonder if anyone could point me in the right direction please? Thanks in advance
Regards
Jerry