[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

use same command again with parameters fails with COUNT of field sysntax error

Jason

8/15/2002 11:53:00 PM

Hi All

I set up a OdbcCommand as my SelectCommand in an Adapter and have one
parameter like so - "select * from mytable where myfield = ?"

I add the paramter to the parameters collection of the OdbcCommand object.

I call a function described below two times. The first time i call it i set
the value of the parameter i added to the paramters collection of the above
command object; before the Adapter in which it is used as a SelectCommand
then gets a fill call on it. This is fine the first time around.

An example but this is from memory and only contains the short definition of
the problem

void MyFunction(int myFieldValue, DataSet ds)
{
MyAdap.SelectCommand.Parameters["MyParamName"].Value = myFieldValue;
MyAdap.Fill(ds);
}

On my next call to this function it very obviously goes through the same
process - using exactly the same adapter and command object as before (they
are the same instances) and i set the parameter value as before (as in the
code) and call fill. This time it fails with a similar message to the one
in the subject line (from memory) which i think we have all seen at some
time or other.

Does this mean a OdbcCommand can not be reused by merely reassigning new
values to the parameters?

For your info: If i were to prepare the statement beforehand then it is
fine - the same parameter in the same command in the same adapter can be set
multiple times and fill called multiple times - its perfect. But that
requires me to keep the connection open to create the prepared statement
which is not the intention for this stateful object instance. The driver i
use is Sql Server (for development) - and i note the SqlClient namespace
objects do not have this same problem?

Anyone got any ideas or understanding on the problem?

Thanks in advance

Jason


4 Answers

laled

8/21/2002 11:43:00 PM

0

Yes, the same command can be re-used again. But you have
to close the dara reader obtained from the first
execution first.

This posting is provided "AS IS" with no warranties, and
confers no rights.

laled
>-----Original Message-----
>Hi All
>
>I set up a OdbcCommand as my SelectCommand in an Adapter
and have one
>parameter like so - "select * from mytable where myfield
= ?"
>
>I add the paramter to the parameters collection of the
OdbcCommand object.
>
>I call a function described below two times. The first
time i call it i set
>the value of the parameter i added to the paramters
collection of the above
>command object; before the Adapter in which it is used
as a SelectCommand
>then gets a fill call on it. This is fine the first
time around.
>
>An example but this is from memory and only contains the
short definition of
>the problem
>
>void MyFunction(int myFieldValue, DataSet ds)
>{
> MyAdap.SelectCommand.Parameters["MyParamName"].Value
= myFieldValue;
> MyAdap.Fill(ds);
>}
>
>On my next call to this function it very obviously goes
through the same
>process - using exactly the same adapter and command
object as before (they
>are the same instances) and i set the parameter value as
before (as in the
>code) and call fill. This time it fails with a similar
message to the one
>in the subject line (from memory) which i think we have
all seen at some
>time or other.
>
>Does this mean a OdbcCommand can not be reused by merely
reassigning new
>values to the parameters?
>
>For your info: If i were to prepare the statement
beforehand then it is
>fine - the same parameter in the same command in the
same adapter can be set
>multiple times and fill called multiple times - its
perfect. But that
>requires me to keep the connection open to create the
prepared statement
>which is not the intention for this stateful object
instance. The driver i
>use is Sql Server (for development) - and i note the
SqlClient namespace
>objects do not have this same problem?
>
>Anyone got any ideas or understanding on the problem?
>
>Thanks in advance
>
>Jason
>
>
>.
>

Jason

8/24/2002 9:36:00 PM

0

actually i can't. the adapter should have done that. it should have opened
the reader - populated the dataset, and then closed the reader. i don't
think the odbc adapter is closing the reader which is why this bug occurs.

cheers

jason

"laled" <laled@nospam.microsoft.com> wrote in message
news:662d01c2495b$c2708200$9ee62ecf@tkmsftngxa05...
> Yes, the same command can be re-used again. But you have
> to close the dara reader obtained from the first
> execution first.
>
> This posting is provided "AS IS" with no warranties, and
> confers no rights.
>
> laled
> >-----Original Message-----
> >Hi All
> >
> >I set up a OdbcCommand as my SelectCommand in an Adapter
> and have one
> >parameter like so - "select * from mytable where myfield
> = ?"
> >
> >I add the paramter to the parameters collection of the
> OdbcCommand object.
> >
> >I call a function described below two times. The first
> time i call it i set
> >the value of the parameter i added to the paramters
> collection of the above
> >command object; before the Adapter in which it is used
> as a SelectCommand
> >then gets a fill call on it. This is fine the first
> time around.
> >
> >An example but this is from memory and only contains the
> short definition of
> >the problem
> >
> >void MyFunction(int myFieldValue, DataSet ds)
> >{
> > MyAdap.SelectCommand.Parameters["MyParamName"].Value
> = myFieldValue;
> > MyAdap.Fill(ds);
> >}
> >
> >On my next call to this function it very obviously goes
> through the same
> >process - using exactly the same adapter and command
> object as before (they
> >are the same instances) and i set the parameter value as
> before (as in the
> >code) and call fill. This time it fails with a similar
> message to the one
> >in the subject line (from memory) which i think we have
> all seen at some
> >time or other.
> >
> >Does this mean a OdbcCommand can not be reused by merely
> reassigning new
> >values to the parameters?
> >
> >For your info: If i were to prepare the statement
> beforehand then it is
> >fine - the same parameter in the same command in the
> same adapter can be set
> >multiple times and fill called multiple times - its
> perfect. But that
> >requires me to keep the connection open to create the
> prepared statement
> >which is not the intention for this stateful object
> instance. The driver i
> >use is Sql Server (for development) - and i note the
> SqlClient namespace
> >objects do not have this same problem?
> >
> >Anyone got any ideas or understanding on the problem?
> >
> >Thanks in advance
> >
> >Jason
> >
> >
> >.
> >


laled

9/4/2002 12:50:00 AM

0

The adapter in general closes the datareader. The fact
that it is left open after a Fill indicates that some
kind of error occured during the Fill, and the operation
was aborted prematurely.
You can get more info on what kind of error occured by
listening to FillError events.

laled

This posting is provided "AS IS" with no warranties, and
confers no rights.


>-----Original Message-----
>actually i can't. the adapter should have done that.
it should have opened
>the reader - populated the dataset, and then closed the
reader. i don't
>think the odbc adapter is closing the reader which is
why this bug occurs.
>
>cheers
>
>jason
>
>"laled" <laled@nospam.microsoft.com> wrote in message
>news:662d01c2495b$c2708200$9ee62ecf@tkmsftngxa05...
>> Yes, the same command can be re-used again. But you
have
>> to close the dara reader obtained from the first
>> execution first.
>>
>> This posting is provided "AS IS" with no warranties,
and
>> confers no rights.
>>
>> laled
>> >-----Original Message-----
>> >Hi All
>> >
>> >I set up a OdbcCommand as my SelectCommand in an
Adapter
>> and have one
>> >parameter like so - "select * from mytable where
myfield
>> = ?"
>> >
>> >I add the paramter to the parameters collection of the
>> OdbcCommand object.
>> >
>> >I call a function described below two times. The first
>> time i call it i set
>> >the value of the parameter i added to the paramters
>> collection of the above
>> >command object; before the Adapter in which it is used
>> as a SelectCommand
>> >then gets a fill call on it. This is fine the first
>> time around.
>> >
>> >An example but this is from memory and only contains
the
>> short definition of
>> >the problem
>> >
>> >void MyFunction(int myFieldValue, DataSet ds)
>> >{
>> > MyAdap.SelectCommand.Parameters
["MyParamName"].Value
>> = myFieldValue;
>> > MyAdap.Fill(ds);
>> >}
>> >
>> >On my next call to this function it very obviously
goes
>> through the same
>> >process - using exactly the same adapter and command
>> object as before (they
>> >are the same instances) and i set the parameter value
as
>> before (as in the
>> >code) and call fill. This time it fails with a
similar
>> message to the one
>> >in the subject line (from memory) which i think we
have
>> all seen at some
>> >time or other.
>> >
>> >Does this mean a OdbcCommand can not be reused by
merely
>> reassigning new
>> >values to the parameters?
>> >
>> >For your info: If i were to prepare the statement
>> beforehand then it is
>> >fine - the same parameter in the same command in the
>> same adapter can be set
>> >multiple times and fill called multiple times - its
>> perfect. But that
>> >requires me to keep the connection open to create the
>> prepared statement
>> >which is not the intention for this stateful object
>> instance. The driver i
>> >use is Sql Server (for development) - and i note the
>> SqlClient namespace
>> >objects do not have this same problem?
>> >
>> >Anyone got any ideas or understanding on the problem?
>> >
>> >Thanks in advance
>> >
>> >Jason
>> >
>> >
>> >.
>> >
>
>
>.
>

Jason

9/7/2002 12:28:00 AM

0

thanks

i haven't tried it - i just went back to oledb. i saw some mention of
service pack 2 fixing an open datareader so i'll try my code again someday.

cheers





<laled@nospam.microsoft.com> wrote in message
news:a84601c253a4$a12bcf20$37ef2ecf@TKMSFTNGXA13...
> The adapter in general closes the datareader. The fact
> that it is left open after a Fill indicates that some
> kind of error occured during the Fill, and the operation
> was aborted prematurely.
> You can get more info on what kind of error occured by
> listening to FillError events.
>
> laled
>
> This posting is provided "AS IS" with no warranties, and
> confers no rights.
>
>
> >-----Original Message-----
> >actually i can't. the adapter should have done that.
> it should have opened
> >the reader - populated the dataset, and then closed the
> reader. i don't
> >think the odbc adapter is closing the reader which is
> why this bug occurs.
> >
> >cheers
> >
> >jason
> >
> >"laled" <laled@nospam.microsoft.com> wrote in message
> >news:662d01c2495b$c2708200$9ee62ecf@tkmsftngxa05...
> >> Yes, the same command can be re-used again. But you
> have
> >> to close the dara reader obtained from the first
> >> execution first.
> >>
> >> This posting is provided "AS IS" with no warranties,
> and
> >> confers no rights.
> >>
> >> laled
> >> >-----Original Message-----
> >> >Hi All
> >> >
> >> >I set up a OdbcCommand as my SelectCommand in an
> Adapter
> >> and have one
> >> >parameter like so - "select * from mytable where
> myfield
> >> = ?"
> >> >
> >> >I add the paramter to the parameters collection of the
> >> OdbcCommand object.
> >> >
> >> >I call a function described below two times. The first
> >> time i call it i set
> >> >the value of the parameter i added to the paramters
> >> collection of the above
> >> >command object; before the Adapter in which it is used
> >> as a SelectCommand
> >> >then gets a fill call on it. This is fine the first
> >> time around.
> >> >
> >> >An example but this is from memory and only contains
> the
> >> short definition of
> >> >the problem
> >> >
> >> >void MyFunction(int myFieldValue, DataSet ds)
> >> >{
> >> > MyAdap.SelectCommand.Parameters
> ["MyParamName"].Value
> >> = myFieldValue;
> >> > MyAdap.Fill(ds);
> >> >}
> >> >
> >> >On my next call to this function it very obviously
> goes
> >> through the same
> >> >process - using exactly the same adapter and command
> >> object as before (they
> >> >are the same instances) and i set the parameter value
> as
> >> before (as in the
> >> >code) and call fill. This time it fails with a
> similar
> >> message to the one
> >> >in the subject line (from memory) which i think we
> have
> >> all seen at some
> >> >time or other.
> >> >
> >> >Does this mean a OdbcCommand can not be reused by
> merely
> >> reassigning new
> >> >values to the parameters?
> >> >
> >> >For your info: If i were to prepare the statement
> >> beforehand then it is
> >> >fine - the same parameter in the same command in the
> >> same adapter can be set
> >> >multiple times and fill called multiple times - its
> >> perfect. But that
> >> >requires me to keep the connection open to create the
> >> prepared statement
> >> >which is not the intention for this stateful object
> >> instance. The driver i
> >> >use is Sql Server (for development) - and i note the
> >> SqlClient namespace
> >> >objects do not have this same problem?
> >> >
> >> >Anyone got any ideas or understanding on the problem?
> >> >
> >> >Thanks in advance
> >> >
> >> >Jason
> >> >
> >> >
> >> >.
> >> >
> >
> >
> >.
> >