Re: Data Reader Error Please Help its Urgent
From: DalePres (don-t-spa-m-me_at_lea-ve-me-a-lone--.com)
Date: 02/04/05
- Next message: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Previous message: Norman Yuan: "Re: which is a better use of the data"
- Next in thread: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: NuTcAsE: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: DalePres: "Re: Data Reader Error Please Help its Urgent"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 4 Feb 2005 09:37:25 -0600
I am just guessing here but probably the DataSet.Fill method calls a
DataReader to do the work.
There are a few possibilities that come to my mind. First, you might create
a non-static method or class so that each user has their own instance rather
than a shared instance. If you must use a static instance, you might try
using a lock statement to block others until the first user is finished with
the code section.
You could wrap your functionality in a using statement, such as
SqlConnection sqlConn = new SqlConnection()
{
}
This makes sure that the connection object is disposed when the using
section is exited.
Also, when I test for connection state, I test with if (conn.ConnectionState
!= ConnectionState.Closed). There are other conditions the ConnectionState
can be other than Open that are still not Closed.
Hope this helps,
DalePres
MCAD, MCDBA, MCSE
"Amit D.Shinde" <amit_sd01@yahoo.com> wrote in message
news:9aee070d.0502040726.302f448b@posting.google.com...
> Hello
>
> I have on clsGlobal.cs File in which i have created many functions of
> Fetching, Inserting Data In Database.. Using Ado.net AsP.net C#.net
> Those Functions returns String, Dataset etc.
> But NO WHERE I AM USING DATAREADER IN WHOLE PROJECT.
>
> But i Get the Error While at a time two users logs in i.e. more than
> one user try to access my webapplication.
>
> The error is as follows:
>
> "There is already an open DataReader associated with this Connection
> which must be closed first. "
> I know why this error occurs .. .due to not closing of connection but
> everywhere i am closing the connection ..
>
> Please Help Me i am sending some samples where error occurss..
>
>
> public static DataSet ExecuteSPDS(SqlCommand pCmd)
> {
> DataSet sResult;
> try
> {
> SqlDataAdapter da = new SqlDataAdapter(pCmd);
> DataSet ds = new DataSet();
> da.Fill(ds,"RECORD");
> sResult = ds;
> }
> catch(System.Exception ex)
> {
> sResult = null;
>
> }
> return sResult;
> }
>
>
>
> ========================================================
> public static string ExecuteScalarQuery1(string query)
> {
> string Result;
> //try
> {
> SqlCommand cmd = new SqlCommand(query,m_Connection);
> if(m_Connection.State==ConnectionState.Closed)
> {
> m_Connection.Open();
> }
> Result=Convert.ToString(cmd.ExecuteScalar());
> if(m_Connection.State==ConnectionState.Open)
> {
> m_Connection.Close();
> }
> //catch(System.Exception ex)
> {
> }
> return Result;
> }
> }
> ====================================================
- Next message: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Previous message: Norman Yuan: "Re: which is a better use of the data"
- Next in thread: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: Dumitru Sbenghe: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: NuTcAsE: "Re: Data Reader Error Please Help its Urgent"
- Maybe reply: DalePres: "Re: Data Reader Error Please Help its Urgent"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|