By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Problem with OleDbConnection Object

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
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

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.