473,386 Members | 1,715 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,386 software developers and data experts.

Enterprise Library 2.0 - ExecuteDataSet doesn't closes the database connection - any idea?

I am using .NET 2.0 along with Data Access Application Block of
Enterprise Library 2.0 in one of my wrapper class and what I observered
is once the connection is left open after execution of ExecuteDataSet
function of Database class.

I used Preformance counter for SQL user connection. When
DataFactroy.CreateDatabase is executed it create a connection but when
Database.ExecuteDataset doesn't closes the connection. Furthermore, if
I close by application then connection is also closed and I can see the
count going down by 1 in the Performace counter. This doesn't happen
when ExecuteDataSet is called.

Following is the code snippet I am using in my wrapper class.

private DataSet ExecuteSp(string storedProc)
{
Database db = DatabaseFactroy.CreateConnection();
DbCommand dbCommand = db.GetStoredProcCommand("any_sp");

//Set the parameter in the command object
db.AddInParameter(dbCommand, "Param1", DbType.String,
"Param_val");

//Execute the sp and generate the dataset
DataSet dataSet;
using (dataSet = db.ExecuteDataSet(dbCommand))

//reset the variables
dbParameter = null;
dbCommand = null;
db = null;

//return dataset
return dataSet;
}

According to documents, ExecuteDataSet closes the connection but as per
my observation on Performace counter it isn't

Does anyone have any idea on how to close the connection once created
by DataFactory.CreateDatabase()?

Dec 28 '06 #1
4 11263
Thanks...it works now...

I can now see the spike in the performance counter and also verified
the connection pooling...thanks a lot..

David Musgrove wrote:
Try disposing the DbCommand like this:

private DataSet ExecuteSp(string storedProc)
{
Database db = DatabaseFactroy.CreateConnection();
using (DbCommand dbCommand = db.GetStoredProcCommand("any_sp"))
{

//Set the parameter in the command object
db.AddInParameter(dbCommand, "Param1", DbType.String,
"Param_val");

//Execute the sp and generate the dataset
DataSet dataSet;
dataSet = db.ExecuteDataSet(dbCommand);
}

//reset the variables
dbParameter = null;
dbCommand = null;
db = null;

//return dataset
return dataSet;
}

D
Dec 28 '06 #2
"David Musgrove" <Da***********@discussions.microsoft.comwrote in message
news:A2**********************************@microsof t.com...
Try disposing the DbCommand like this:

private DataSet ExecuteSp(string storedProc)
{
Database db = DatabaseFactroy.CreateConnection();
using (DbCommand dbCommand = db.GetStoredProcCommand("any_sp"))
{

//Set the parameter in the command object
db.AddInParameter(dbCommand, "Param1", DbType.String,
"Param_val");

//Execute the sp and generate the dataset
DataSet dataSet;
dataSet = db.ExecuteDataSet(dbCommand);
}

//reset the variables
dbParameter = null;
dbCommand = null;
db = null;
Setting local variables to null serves no purpose other than deliberate code
bloat. The variables become available for collection after the last
reference (even before the method returns), so there's nothing to be gained
by setting them to null just before the method ends.

-cd
Dec 29 '06 #3
"Carl Daniel [VC++ MVP]"
>//reset the variables
dbParameter = null;
dbCommand = null;
db = null;

Setting local variables to null serves no purpose other than deliberate
code bloat. The variables become available for collection after the last
reference (even before the method returns), so there's nothing to be
gained by setting them to null just before the method ends.
Even worse, setting them to null actually keeps them around longer. If
you're running in Release Mode, then the GC would clean those variables up
as soon as it hit the last line that references them. (In debug mode, this
isn't the case, as it would make debugging practically impossible, and so
they use scope instead).

By doing this, the originally poster is making that "last reference" further
down in the method, thereby extending the lifetimes of those variables.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Dec 29 '06 #4
Mea culpa!

I had only read far enough to identify the problem, and had persisted these
"set to null" lines by the powers of copy and paste.

D
Dec 29 '06 #5

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

Similar topics

1
by: Mike Chamberlain | last post by:
Hi all. I'm trying to extend the Microsoft Enterprise Library Data Access Application Block (http://msdn.microsoft.com/library/en-us/dnpag2/html/daab.asp?frame=true) to work with a Borland...
0
by: ad | last post by:
I have used Data Application Access Block2 in my web application. Now I download the Library Data Access Application Block. and read the document. May be I am stupid, I can't migrate it to...
0
by: jb | last post by:
Is it possible to keep a connection to the database open whilst using the enterprise library Database methods like ExecuteDataSet(), ExecuteScalar() etc in a loop without using transactions (or...
7
by: galico | last post by:
Hi All, We are having a very strange problem with the above. We have designed an application in ASP.NET 2.0 that uses the enterprise library data application blocks amongst others. We seem to be...
0
by: TattedProgrammer | last post by:
Hello All, I am completely stuck, I have tried for an entire day to get a simple procedure call to my Oracle Db via the enterprise Library 06. I am not an oracle fan to start, but have to deal...
1
by: Victor | last post by:
Hi guys I have a question here. I am currently using Enterprise Library Jan 2006 version. I found out where i execute the Database.executeDataSet() the Enterprise Library will not close the...
0
by: nostradumbass77 | last post by:
Using Enterprise Library 2.0 (Jan 06) and .NET 2.0 (VB.Net 2005) Dim dbPF As Data.Common.DbProviderFactory Try dbPF = Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb") db = New...
4
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I downloaded enterprise library 2.0 , 2006 today . I followed all the instructions that were given in the documentation. I tried to follow everything that was mentioned in...
2
by: kellygreer1 | last post by:
I'm working on some internal company web services and I have a question about resource management within the Enterprise Data Access Block. I have about 20 methods which look similar to the one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.