473,651 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Closing of OleDbConnection and OleDbDataReader

Hi,

if have this method in a cs file that connections to a
database and returns a datareader to my web form.

public OleDbDataReader GetDataReader(s tring theSQL)
{
theConn = new OleDbConnection (ConnectionStri ng);
theConn.Open();
OleDbCommand cmd = new OleDbCommand(th eSQL, theConn);
OleDbDataReader theResult = cmd.ExecuteRead er
(CommandBehavio r.CloseConnecti on);
return theResult;
}

in the aspx file, after getting the result of this Query
method, i will close the datareader. Is this adequate? do
i need to close the OleDbConnection as well? if so, how
can i point to the OleDbConnection ?
I realise that my database has got a series of open
connection which i suspect is caused by my web application.

thanks for any help
Nov 18 '05 #1
1 1962
hi,
I've had similar problems where connections that I've
expected to be closed implicitly by asp.net remain open.
A good solution is to wrapper your data access routine
into a class, making the connection object a global
variable that is opened in your class constructor.
Then write a dispose method for the class (which must
implement the IDisposable interface) which closes the
connection and destroys the object.
Make sure you call the dispose method of your class after
you have finished with it - the asp.net garbage collector
is unreliable.

alex
-----Original Message-----
Hi,

if have this method in a cs file that connections to a
database and returns a datareader to my web form.

public OleDbDataReader GetDataReader(s tring theSQL)
{
theConn = new OleDbConnection (ConnectionStri ng);
theConn.Open();
OleDbCommand cmd = new OleDbCommand(th eSQL, theConn);
OleDbDataReader theResult = cmd.ExecuteRead er
(CommandBehavi or.CloseConnect ion);
return theResult;
}

in the aspx file, after getting the result of this Query
method, i will close the datareader. Is this adequate? doi need to close the OleDbConnection as well? if so, how
can i point to the OleDbConnection ?
I realise that my database has got a series of open
connection which i suspect is caused by my web application.
thanks for any help
.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1296
by: Grant | last post by:
My C# web application connects to an Access database using the OleDbConnection and OleDbDataReader. I have 3 other computers that connect to this server but very frequently I get an 'Unspecified error' message and the site becomes unusable. I have customErrors set to 'Off' so I can see what bit of code it is crashing at and it is always at line 78 below. (If I try and start a debug session - the server seems to reset itself and goes back...
2
2864
by: Grant | last post by:
My C# web application connects to an Access database using the OleDbConnection and OleDbDataReader. I have 3 other computers that connect to this server but very frequently I get an 'Unspecified error' message and the site becomes unusable. I have customErrors set to 'Off' so I can see what bit of code it is crashing at and it is always at line 78 below. (If I try and start a debug session - the server seems to reset itself and goes back...
4
7673
by: Jeff User | last post by:
Hi all I am using an OleDbDataReader. I need to establish and then keep the connection that I use, but I do not need to keep the data reader, after this operation is over. Therefore, regardless of failure or not, I need to close the data reader. So, in trying to practice good habits (and if I dont it causes an error the next time around) I close the reader before exiting this procedure. This is fine until I need to handle errors. So, I...
0
1128
by: Brent | last post by:
I wrote a simple class to supply a datareader object (code at bottom of post) back to a page. I access it on the APSX page like this: Dim myDR as New getDataReader(strSQL) If myDR.ResultFailed = True Then MessageText.InnerHTML = "Internal error." Else
3
1792
by: Ludvig | last post by:
This Exception is executed when using SQLConnection. OleDbConnection connects fine. System.EnterpriseServices.Platform.Initialize() +503 System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate cb) +11 System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl ctrl) +797 System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl ctrl) +170
7
4124
by: Arsalan | last post by:
I have a function which return datareader Public Shared Function ReturnDReader(ByVal query As String) As OleDbDataReader Dim Connection_String As String = System.Configuration.ConfigurationSettings.AppSettings("strConn") Dim conn As OleDbConnection Dim cm As OleDbCommand Dim dr As OleDbDataReader Try
6
4227
by: bokiteam | last post by:
Hi All, I have this error msg, but I have already import lib, could you please advice? Imports System.Data.OleDb Public Class Form1 Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader
1
1488
by: Jerry Spence1 | last post by:
I have been doing the following is VB.Net 2003: Dim dr1 As OleDbDataReader .....Code here If Not dr1 Is Nothing Then
1
2079
by: Mel | last post by:
I am performing the same recordset multiple times, just passing different parameters each time. Is there a way to do this more efficiently without having to close and re-open the connection and reader? I thought there might be a cleaner way, this code seems to take "forever" to run. '-------BEGINNING OF CODE EXAMPLE------- Dim SBInvNum As String Dim strConInv As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source =" &...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.