Problem with OleDbConnection Object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written the following function which returns OleDbConnection object.
If global variable g_strDbPath contains an invalid file name or path name the
catch block throws an error with appropriate error message, but if
g_strDbPath is blank then the catch block throws an error saying “No error
information available: DB_SEC_E_AUTH_FAILED(0x80040E4D).†In this case
connection string is incorrect so why doesn’t it throws as appropriate error
message?

Public Function CreateConnection() As OleDbConnection
Try
Dim cnn As OleDbConnection
Dim strCnn As String

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& g_strDbPath

'! Initialize connection object.
cnn = New OleDbConnection(strCnn)

Return cnn

Catch ex As Exception
Throw ex
End Try

End Function
 
First - I'd do a File.Exists before setting the connection string - if the
file is wrong/empty/doesn't exist - then handle it accordingly don't go
ahead and throw an exception ---

Next - don't catch system.exception here - throw an OleDbException - if you
get a StackOverflow exception for instance you wouldn't handle it the same
way as a bad connection string.

I think the answer to your question though is that there is no information
on this if it's blank.
 
Back
Top