ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel suddenly closes when a DSN-Less connection to SQLServer fails (https://www.excelbanter.com/excel-programming/388227-excel-suddenly-closes-when-dsn-less-connection-sqlserver-fails.html)

Luis Porras

Excel suddenly closes when a DSN-Less connection to SQLServer fails
 
Hi,

I'm using a function to retrieve data from SQL Server (2000) with Excel
2003, the connection string I'm using is the following...

On Error Resume Next
Set Connect = CreateObject("ADODB.Connection")

OdbcDSN = "Driver={SQL
Server};SERVER=hostname\name;UID=sa;DATABASE=mydb"

Connect.Open OdbcDSN '--------------- The Excel just closes here!

If Connect.Errors.Count < 0 Then
For Each objError In Connect.Errors
If objError.NativeError < 5701 And objError.NativeError < 5703
Then ' Ignore the success warnings
Connect.Close
GoTo Continue
End If
Next
End If

The problem is that I want to handle if the user can't reach the SQL Server
(for any reason) so the function will continue executing the rest of the
tasks but, when the function tries to open the connection, excel simply
closes, with no error, no warnings... nothing at all.

~Luis

Thanks!




All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com