Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with OleDbConnection Object

Status
Not open for further replies.

meinhunna

Programmer
Jul 31, 2004
118
0
0
AU
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

How can I catch this error so that I can provide customized error message?
 
If you want more information try
Try

Catch ex As System.Data.OleDb.OleDbException

End Try

As this will give better information on the error message. You could also add the line

if g_strDbPath = "" then
throw new exception("database path is empty")
end if
 
I have tried using

Catch ex As System.Data.OleDb.OleDbException

It gives same error message as Exception, i wud try the second option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top