PeterT
November 9th, 2000, 02:02 PM
It seems strange to me that the Connection object doesn't expect failed connections and that this has to be trapped with On Error. Am I missing something?
|
Click to See Complete Forum and Search --> : Trapping ADO connection error PeterT November 9th, 2000, 02:02 PM It seems strange to me that the Connection object doesn't expect failed connections and that this has to be trapped with On Error. Am I missing something? Andrew R. November 15th, 2000, 04:44 PM What type of DB engine you're connectin to? PeterT November 15th, 2000, 06:20 PM SQL Server Andrew R. November 15th, 2000, 08:56 PM In this case I had the same problem. So, to catch errors during connection I use this function before connecting with ADO. '------------------------------------------------------------------------------------ private Function lConnectSQLDB(strServer_p as string, _ strLogin_p as string, _ strPassw_p as string) as Long ' ' tries to connect to SQL DB, returns meaningful error if not successfully '------------------------------------------------------------------------------------ on error GoTo ErrorHandler ' ' to connect to SQL Server/MSDE Dim oSQLServer as Object set oSQLServer = CreateObject("SQLDMO.SQLServer") ' ' set timeout oSQLServer.LoginTimeout = 60 ' ' try to connect oSQLServer.Connect strServer_p, strSQLLogin_g, strPassw_p ' ' close connection if it was successful oSQLServer.Close lConnectSQLDB = 0 ' Exit Function ' ErrorHandler: oSQLServer.Close lConnectSQLDB = Err.Number Select Case Err.Number Case 18456 ' we're here if SQL Server refused provided login and password Case 440 ' we're here if SQL Server doesn't respond (doesn't exist) Case 429 ' we're here if user doesn't have SQL client Case else MsgBox Err.Number, Err.Description, vbCritical End Select End Function To use this SQLDMO stuff your PC should have installed SQL Server or MSDE or SQL client. Or none of these, but several dll's in special place. I'm glad, if it will help you. PeterT November 16th, 2000, 12:05 PM Thank you for the code. I created a similar function using the ADO connection object. But that doesn't provide me with any specifics on the nature of the error. I'll check out SQLDMO. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |