I have 2 data adapters, 1 connection , and one data set. I use the same
connection for all this data adapters. I'm using an access database and
windows forms

when I change from one record to other on the table JOBS it triggers
one event. In this event, I have a code like



System.Windows.Forms.BindingManagerBase bc;

bc = this.BindingContext[this.ds1, "jobs"];



this.ds1.WorkEmp.Clear();

if (bc.Count>0)
{
System.Data.DataRow drv;

drv = this.ds1.jobs.Rows[bc.Position];
this.daWorkEmp.SelectCommand.Parameters["njob"].Value=Convert.ToInt16(drv["njob"]);
try
{
this.daWorkEmp.Fill(this.ds1.WorkEmp); // ERROR HAPPENS HERE
}
catch (Exception e3)
{
MessageBox.Show(e3.ToString());
return ;
}
}


I got this message


"System.invalidOperationException: there is already an open DataReader
associated with this connection which must closed first"



WorkEmp.SelectCommand is like

SELECT b.firstname, b.lastname, a.empid, a.njob, b.empid AS Expr1 FROM
WorkOn a INNER JOIN employee b ON a.empid = b.empid WHERE (a.njob = ?)


I'm missing something???

I use the same logic in other modules and it works.
I'm not using any DataReader!!!
i'm not opening or closing by code the connection!!




TIA

Re: System.invalidOperationException by Joyjit

Joyjit
Wed Aug 18 01:51:45 CDT 2004

Hi,

Are you setting your DA.SelectCommand property from an existing Command
object which has a DataReader associated with it ? If yes, close the Reader
first.

Regards
Joyjit


"fanor" <xreed2000@yahoo.com> wrote in message
news:O2ajL6LhEHA.1392@TK2MSFTNGP11.phx.gbl...
> I have 2 data adapters, 1 connection , and one data set. I use the same
> connection for all this data adapters. I'm using an access database and
> windows forms
>
> when I change from one record to other on the table JOBS it triggers
> one event. In this event, I have a code like
>
>
>
> System.Windows.Forms.BindingManagerBase bc;
>
> bc = this.BindingContext[this.ds1, "jobs"];
>
>
>
> this.ds1.WorkEmp.Clear();
>
> if (bc.Count>0)
> {
> System.Data.DataRow drv;
>
> drv = this.ds1.jobs.Rows[bc.Position];
>
this.daWorkEmp.SelectCommand.Parameters["njob"].Value=Convert.ToInt16(drv["n
job"]);
> try
> {
> this.daWorkEmp.Fill(this.ds1.WorkEmp); // ERROR HAPPENS HERE
> }
> catch (Exception e3)
> {
> MessageBox.Show(e3.ToString());
> return ;
> }
> }
>
>
> I got this message
>
>
> "System.invalidOperationException: there is already an open DataReader
> associated with this connection which must closed first"
>
>
>
> WorkEmp.SelectCommand is like
>
> SELECT b.firstname, b.lastname, a.empid, a.njob, b.empid AS Expr1 FROM
> WorkOn a INNER JOIN employee b ON a.empid = b.empid WHERE (a.njob = ?)
>
>
> I'm missing something???
>
> I use the same logic in other modules and it works.
> I'm not using any DataReader!!!
> i'm not opening or closing by code the connection!!
>
>
>
>
> TIA
>



Re: System.invalidOperationException by Fanor

Fanor
Wed Aug 18 08:54:11 CDT 2004

I found out what is happening I have a da1.fill , this triggers the event
in which I have another da2.fill , so at that time the connection is opened.
So, the question is, do I have to use a different connection for each data
adapter??
if that is the case, transactions will be use only one table at any time,
which doesn't make sence!!
there must another way, please advice

Thanks

"Joyjit Mukherjee" <joyjit_mukherjee@hotmail.com> wrote in message
news:eQGbV$OhEHA.1972@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> Are you setting your DA.SelectCommand property from an existing Command
> object which has a DataReader associated with it ? If yes, close the
Reader
> first.
>
> Regards
> Joyjit
>
>
> "fanor" <xreed2000@yahoo.com> wrote in message
> news:O2ajL6LhEHA.1392@TK2MSFTNGP11.phx.gbl...
> > I have 2 data adapters, 1 connection , and one data set. I use the same
> > connection for all this data adapters. I'm using an access database and
> > windows forms
> >
> > when I change from one record to other on the table JOBS it triggers
> > one event. In this event, I have a code like
> >
> >
> >
> > System.Windows.Forms.BindingManagerBase bc;
> >
> > bc = this.BindingContext[this.ds1, "jobs"];
> >
> >
> >
> > this.ds1.WorkEmp.Clear();
> >
> > if (bc.Count>0)
> > {
> > System.Data.DataRow drv;
> >
> > drv = this.ds1.jobs.Rows[bc.Position];
> >
>
this.daWorkEmp.SelectCommand.Parameters["njob"].Value=Convert.ToInt16(drv["n
> job"]);
> > try
> > {
> > this.daWorkEmp.Fill(this.ds1.WorkEmp); // ERROR HAPPENS HERE
> > }
> > catch (Exception e3)
> > {
> > MessageBox.Show(e3.ToString());
> > return ;
> > }
> > }
> >
> >
> > I got this message
> >
> >
> > "System.invalidOperationException: there is already an open DataReader
> > associated with this connection which must closed first"
> >
> >
> >
> > WorkEmp.SelectCommand is like
> >
> > SELECT b.firstname, b.lastname, a.empid, a.njob, b.empid AS Expr1 FROM
> > WorkOn a INNER JOIN employee b ON a.empid = b.empid WHERE (a.njob = ?)
> >
> >
> > I'm missing something???
> >
> > I use the same logic in other modules and it works.
> > I'm not using any DataReader!!!
> > i'm not opening or closing by code the connection!!
> >
> >
> >
> >
> > TIA
> >
>
>



Re: System.invalidOperationException by Joyjit

Joyjit
Thu Aug 19 01:46:55 CDT 2004

Hi,

try trapping the FillError event of the DataAdapter like this:-
protected static void FillError(object sender, FillErrorEventArgs e)
{
if (e.Errors.GetType() == typeof(System.invalidOperationException))
{
e.Continue = true;
}
}

Regards
Joyjit

"Fanor" <xreed2000@yahoo.com> wrote in message
news:ObrShrShEHA.2416@TK2MSFTNGP10.phx.gbl...
> I found out what is happening I have a da1.fill , this triggers the event
> in which I have another da2.fill , so at that time the connection is
opened.
> So, the question is, do I have to use a different connection for each
data
> adapter??
> if that is the case, transactions will be use only one table at any time,
> which doesn't make sence!!
> there must another way, please advice
>
> Thanks
>
> "Joyjit Mukherjee" <joyjit_mukherjee@hotmail.com> wrote in message
> news:eQGbV$OhEHA.1972@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > Are you setting your DA.SelectCommand property from an existing Command
> > object which has a DataReader associated with it ? If yes, close the
> Reader
> > first.
> >
> > Regards
> > Joyjit
> >
> >
> > "fanor" <xreed2000@yahoo.com> wrote in message
> > news:O2ajL6LhEHA.1392@TK2MSFTNGP11.phx.gbl...
> > > I have 2 data adapters, 1 connection , and one data set. I use the
same
> > > connection for all this data adapters. I'm using an access database
and
> > > windows forms
> > >
> > > when I change from one record to other on the table JOBS it triggers
> > > one event. In this event, I have a code like
> > >
> > >
> > >
> > > System.Windows.Forms.BindingManagerBase bc;
> > >
> > > bc = this.BindingContext[this.ds1, "jobs"];
> > >
> > >
> > >
> > > this.ds1.WorkEmp.Clear();
> > >
> > > if (bc.Count>0)
> > > {
> > > System.Data.DataRow drv;
> > >
> > > drv = this.ds1.jobs.Rows[bc.Position];
> > >
> >
>
this.daWorkEmp.SelectCommand.Parameters["njob"].Value=Convert.ToInt16(drv["n
> > job"]);
> > > try
> > > {
> > > this.daWorkEmp.Fill(this.ds1.WorkEmp); // ERROR HAPPENS HERE
> > > }
> > > catch (Exception e3)
> > > {
> > > MessageBox.Show(e3.ToString());
> > > return ;
> > > }
> > > }
> > >
> > >
> > > I got this message
> > >
> > >
> > > "System.invalidOperationException: there is already an open DataReader
> > > associated with this connection which must closed first"
> > >
> > >
> > >
> > > WorkEmp.SelectCommand is like
> > >
> > > SELECT b.firstname, b.lastname, a.empid, a.njob, b.empid AS Expr1 FROM
> > > WorkOn a INNER JOIN employee b ON a.empid = b.empid WHERE (a.njob = ?)
> > >
> > >
> > > I'm missing something???
> > >
> > > I use the same logic in other modules and it works.
> > > I'm not using any DataReader!!!
> > > i'm not opening or closing by code the connection!!
> > >
> > >
> > >
> > >
> > > TIA
> > >
> >
> >
>
>