Hello there people,
I'm having some kind of problem. I have a function that returns a
datareader. At some point using the application I get an error
"Unspecified error" (ssssoooo helpful) :). I think I know the problem.
My Connection remains open.
Is there a way I can do to close the Connection. below is the code.
Thank you very much as always
public System.Data.OleDb.OleDbDataReader DataReaderFunc(string
SQLSelect)
{
OleDbDataReader objDataRead = null;
OleDbConnection objConn = new OleDbConnection();
objConn.Close();
objConn.ConnectionString = GetConnection();
OleDbCommand objComm = new OleDbCommand(SQLSelect, objConn);
objConn.Open();
objDataRead = objComm.ExecuteReader(CommandBehavior.CloseConnect ion);
Console.WriteLine (objConn.State);
//objConn.Dispose();
return objDataRead;
} 5 2029
Your Connection remains open, alright. Worse than that, its scoped inside a
method, so when your method exits, you lose any handle on it you had while
the method was executing.
A DataReader requires a persistent Connection. For the entire time you use a
DataReader, its Connection must remain open. Therefore, you need to declare
your Connection outside of the method, so that when you are finished with
the DataReader, you can close the Connection.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
"Varangian" <of****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Hello there people,
I'm having some kind of problem. I have a function that returns a datareader. At some point using the application I get an error "Unspecified error" (ssssoooo helpful) :). I think I know the problem. My Connection remains open.
Is there a way I can do to close the Connection. below is the code. Thank you very much as always
public System.Data.OleDb.OleDbDataReader DataReaderFunc(string SQLSelect) { OleDbDataReader objDataRead = null; OleDbConnection objConn = new OleDbConnection();
objConn.Close(); objConn.ConnectionString = GetConnection(); OleDbCommand objComm = new OleDbCommand(SQLSelect, objConn);
objConn.Open(); objDataRead = objComm.ExecuteReader(CommandBehavior.CloseConnect ion);
Console.WriteLine (objConn.State); //objConn.Dispose(); return objDataRead; }
He is passing in ConnectionBehavior.CloseConnection. So as long as the data
reader is closed, so will the connection, and that will avoid a connection
leak. This means that the connection is fine declared where it is.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:es*************@TK2MSFTNGP14.phx.gbl... Your Connection remains open, alright. Worse than that, its scoped inside a method, so when your method exits, you lose any handle on it you had while the method was executing.
A DataReader requires a persistent Connection. For the entire time you use a DataReader, its Connection must remain open. Therefore, you need to declare your Connection outside of the method, so that when you are finished with the DataReader, you can close the Connection.
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer You can lead a fish to a bicycle, but it takes a very long time, and the bicycle has to *want* to change.
"Varangian" <of****@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... Hello there people,
I'm having some kind of problem. I have a function that returns a datareader. At some point using the application I get an error "Unspecified error" (ssssoooo helpful) :). I think I know the problem. My Connection remains open.
Is there a way I can do to close the Connection. below is the code. Thank you very much as always
public System.Data.OleDb.OleDbDataReader DataReaderFunc(string SQLSelect) { OleDbDataReader objDataRead = null; OleDbConnection objConn = new OleDbConnection();
objConn.Close(); objConn.ConnectionString = GetConnection(); OleDbCommand objComm = new OleDbCommand(SQLSelect, objConn);
objConn.Open(); objDataRead = objComm.ExecuteReader(CommandBehavior.CloseConnect ion);
Console.WriteLine (objConn.State); //objConn.Dispose(); return objDataRead; }
Ah, yes. Sorry, overlooked it.
Well, the only thing left is whether or not he's closing the DataReader
outside the method somewhere.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
"Marina" <so*****@nospam.com> wrote in message
news:uu*************@TK2MSFTNGP10.phx.gbl... He is passing in ConnectionBehavior.CloseConnection. So as long as the data reader is closed, so will the connection, and that will avoid a connection leak. This means that the connection is fine declared where it is.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message news:es*************@TK2MSFTNGP14.phx.gbl... Your Connection remains open, alright. Worse than that, its scoped inside a method, so when your method exits, you lose any handle on it you had while the method was executing.
A DataReader requires a persistent Connection. For the entire time you use a DataReader, its Connection must remain open. Therefore, you need to declare your Connection outside of the method, so that when you are finished with the DataReader, you can close the Connection.
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer You can lead a fish to a bicycle, but it takes a very long time, and the bicycle has to *want* to change.
"Varangian" <of****@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... Hello there people,
I'm having some kind of problem. I have a function that returns a datareader. At some point using the application I get an error "Unspecified error" (ssssoooo helpful) :). I think I know the problem. My Connection remains open.
Is there a way I can do to close the Connection. below is the code. Thank you very much as always
public System.Data.OleDb.OleDbDataReader DataReaderFunc(string SQLSelect) { OleDbDataReader objDataRead = null; OleDbConnection objConn = new OleDbConnection();
objConn.Close(); objConn.ConnectionString = GetConnection(); OleDbCommand objComm = new OleDbCommand(SQLSelect, objConn);
objConn.Open(); objDataRead = objComm.ExecuteReader(CommandBehavior.CloseConnect ion);
Console.WriteLine (objConn.State); //objConn.Dispose(); return objDataRead; }
In my experience, when there is a connection leak and there is a problem
obtaining a new connection, the error message is usually something that
mentions timing out getting a new connection from the connection pool.
Also, database errors will usually have more information other then
'unspecified error'. Are you sure this is the complete error message in the
exception being thrown?
To avoid connection leaks in this type of code, you should make sure you
close the datareader in whatever code is calling this function, to make sure
that the connection the data reader is using is closed.
"Varangian" <of****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Hello there people,
I'm having some kind of problem. I have a function that returns a datareader. At some point using the application I get an error "Unspecified error" (ssssoooo helpful) :). I think I know the problem. My Connection remains open.
Is there a way I can do to close the Connection. below is the code. Thank you very much as always
public System.Data.OleDb.OleDbDataReader DataReaderFunc(string SQLSelect) { OleDbDataReader objDataRead = null; OleDbConnection objConn = new OleDbConnection();
objConn.Close(); objConn.ConnectionString = GetConnection(); OleDbCommand objComm = new OleDbCommand(SQLSelect, objConn);
objConn.Open(); objDataRead = objComm.ExecuteReader(CommandBehavior.CloseConnect ion);
Console.WriteLine (objConn.State); //objConn.Dispose(); return objDataRead; }
Unspecified error
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Unspecified error
-
Line 54: OleDbCommand objComm = new OleDbCommand(SQLSelect,
objConn);
Line 55:
Line 56: objConn.Open();
Line 57: objDataRead =
objComm.ExecuteReader(System.Data.CommandBehavior. CloseConnection);
This is the error I'm getting. with the
ExecuteFunction(CloseConnection) the application lasts a bit more..
however there's still something wrong and the error points into the
objConn.Open();
:) Thanks for the Help This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sam |
last post by:
Hello group,
I have a function which is used to initiate sqlDataReader
object.
I was trying to invoke the close method on the DataReader object but
cant really do that as the function returns a...
|
by: Daniel |
last post by:
TcpClient close() method socket leak
when i use TcpClient to open a connection, send data and close the TcpClient
with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket
on...
|
by: No_Excuses |
last post by:
All,
I am interested in reading the text of a web page and parsing it.
After searching on this newgroup I decided to use the following:
******************************* START OF CODE...
|
by: Chris Tanger |
last post by:
Context:
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed...
|
by: Pierson C |
last post by:
I am developing on a website that is utilizing SQL Server 2000. Shortly
after deploying the site, we began having timeout issues due to the max
connections.
1st instinct was to diligently tidy...
|
by: Eric Sabine |
last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET
connection object, SQLConnection to be exact) and then I came across the
following in some microsoft code.
If Not cn Is Nothing...
|
by: bonita |
last post by:
In my ASP.NET page, I have 2 checkboxes for users to choose which
crystal report they want to display. These two reports use different
tables. If report1 has been choosen and displayed in the...
|
by: Alan Silver |
last post by:
Hello,
I have a generic method in a utility class that grabs an sqldatareader
and returns it. Due to the fact that (AFAIK), you can't close the
database connection before you've read the data,...
|
by: Greg Strong |
last post by:
Hello All,
The short questions are
1 Do you know how to make DSN connection close in Access to Oracle 10g
Express Edition?
&/or
2 Do you know how to make a DSN-less pass-through query...
|
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...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |