ADO.NET Hanging Connections?

  • Thread starter Thread starter Aaron Ruhnow
  • Start date Start date
A

Aaron Ruhnow

I apologize in advance for the "newbie" question.

I have a simple ASP.NET application connecting to an access database.
On one page, the database is queried about 10 times each time it is
loaded. I have found that the page reads the DB and loads correctly
the first 4 times the page is loaded, but on the fifth time I receive
the always helpful error message "System.Data.OleDb.OleDbException:
Unspecified error".

I'm not sure what the problem is..I am sure the queries are correct
since the exact same queries run each time the page is loaded. My
guess is I am not disposing/closing the objects correctly and
connections to the database are hanging and I reach the maximum
allowed.

All the reads are from the OleDbDataReader object. The shared
function that performs the read is:

--------------------------------------------
Dim oUpdCmd As OleDbCommand
Dim tmpDR As OleDbDataReader
Dim m_oCn As OleDb.OleDbConnection

m_oCn = Nothing
m_oCn = New OleDbConnection(myAccessConnString)
m_oCn.Open()
oUpdCmd = New OleDbCommand(sSql, m_oCn)
tmpDR = oUpdCmd.ExecuteReader()

Return tmpDR
--------------------------------------------

Just in case, I Close() the Connection and DataReader objects as soon
as I am done with them. Is there something else that needs to be
done? I did not see any type of Close method attached to the
OleDbCommand object.

Also, my connection string is:
Provider=microsoft.jet.oledb.4.0;Data Source=C:\MyDB.mdb;

Thanks for the help.
 
Be sure to create the DataReader object with the option
"commandbehavior.closeconnection". This will ensure that the connection
used by the DataReader object is actually closed when the
DataReader.Close() method is called. Otherwise it may not be.

Hope this helps.

Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies

This posting is provided "AS IS" with no warranties, and confers no rights.

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026?  If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026.
 
The other problem you might be experiencing is the fact that JET (access
databases) were never intended to be used on ASP sites. JET is
single-threaded and cannot service more than one client at a time. Once it
gets overloaded bad things happen--as you describe.

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Adding CommandBehavior.CloseConnection seems to have done the trick.
This is just a prototype and definitely not anythign to be used in the
"real world." It was just frustrating to have it choke on just a few
queries.

Thanks for the info!

Aaron Ruhnow
 
Back
Top