473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with OleDbConnection Object

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
1 2118
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
0
by: Albert | last post by:
******************** My code: ******************** <%@ Page Language="VB" debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script...
9
by: Nathan Sokalski | last post by:
I am trying to connect to a Microsoft Access Database from my ASP.NET Application. I use the following code to create my connection string: cmdSelect.Connection = New...
1
by: Job Lot | last post by:
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...
0
by: bw171 | last post by:
Hopefully, I frame this problem/question correctly. I have some code written/updated in visual studio 2003. This code when setup on other machines where I have installed the Oracle 9i client, and...
13
by: slinky | last post by:
I'm working on a problem with a form with 6 textboxes and a submit button for adding data to an Access database.I changed a few things and got it down to 1 error!. I have a Sub Page_Load and a Sub...
4
by: slinky | last post by:
I'm making a OLE DB connection in code and was wondering if anyone could identify what the syntax errors I have. I've tried countless combinations and all give errors. New...
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.