A
AndyNakamura
Guest
I have a vb.net application that connects to an access database.
There are various things that could cause an exception when opening a connection, such as the network being down, The oledb provider not being registered and the actual database file not being found.
I'd like to take different actions depending on the error thrown.
What is the best way of doing this?
A couple of examples below. First one by uninstalling AccessDatabaseEngine, the other by disconnecting the network.
System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
System.Data.OleDb.OleDbException (0x80004005): Your network access was interrupted.
Public Function fOpenCon(strCaller As String) As Boolean
fOpenCon = False
Dim dbLoadSource As String
dbLoadSource = "|DataDirectory|\CheckCon.accdb"
Dim pSwRD As String
pSwRD = ""
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & dbLoadSource & "';Jet OLEDBatabase Password='" & pSwRD & "';Mode=Share Deny None"
Try
con.Open()
fOpenCon = True
Catch ex As Exception
MsgBox(strCaller & vbCrLf & ex.ToString)
fOpenCon = False
End Try
End Function
Cheers Andy
Continue reading...
There are various things that could cause an exception when opening a connection, such as the network being down, The oledb provider not being registered and the actual database file not being found.
I'd like to take different actions depending on the error thrown.
What is the best way of doing this?
A couple of examples below. First one by uninstalling AccessDatabaseEngine, the other by disconnecting the network.
System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
System.Data.OleDb.OleDbException (0x80004005): Your network access was interrupted.
Public Function fOpenCon(strCaller As String) As Boolean
fOpenCon = False
Dim dbLoadSource As String
dbLoadSource = "|DataDirectory|\CheckCon.accdb"
Dim pSwRD As String
pSwRD = ""
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & dbLoadSource & "';Jet OLEDBatabase Password='" & pSwRD & "';Mode=Share Deny None"
Try
con.Open()
fOpenCon = True
Catch ex As Exception
MsgBox(strCaller & vbCrLf & ex.ToString)
fOpenCon = False
End Try
End Function
Cheers Andy
Continue reading...