But most importantly It is not giving this exception all the time.sometimes it is not throwing this exception and working fine.But sometimes it is throwing this exception.
This probably doesn't help but make sure the connection is open before you execute the reader. I can't tell from your code if its opened before or how that's handled but conceivably if your connection is global or class level you could have a situation
where the connection is closed when you try to execute the reader. As i said, this probably isn't it but its the most common reason I recieve this error.
Generally this occurs when your SQL statement returns no values, the reader has nothing to read. Which would also exlplain why it works sometimes, and it doesn't work other times.
I have the same problem too. I agree with your statement completely. So whats the best thing to do? I thing catching the error is only option to take. Tell me if you agree.
data reader requires an open connection since it works on connected architecture.check if the connection is opened. If the rows u r trying to read is locked by someother transaction, i guess oracle might throw this error, Check if u can give nolock hint
with select statement.
I would suggest u to use disconnected architecture, usage of datasets. It is easy and simple. It reduces the load on database server. It gets the data and closes the connection automatically. In connected architecture i.e data reader the connection has to
be remained open till all ur business logic is completed.
None
0 Points
6 Posts
Operation is not valid due to the current state of the object using the dataReader
Mar 20, 2006 02:17 AM|onlineanuj|LINK
I am using .net Framework 1.1.In my application I am facing a problem.
It is giving an Exception as
"Operation is not valid due to the current state of the object.,Oracle.DataAccess"
when I am Trying to do This:
Imports oracle.DataAccess.Client
Dim MyCommand As OracleCommand
Dim sqlStateMent As String="select a_1,a_2 from Table "
MyCommand = New OracleCommand(sqlStatement, myConnection)Dim Reader As OracleDataReader
Reader=MyCommand.ExecuterReader(CommandBehavior.Default)
But most importantly It is not giving this exception all the time.sometimes it is not throwing this exception and working fine.But sometimes it is throwing this exception.
Please help me.
Member
11 Points
171 Posts
ASPInsiders
Re: Operation is not valid due to the current state of the object using the dataReader
Mar 28, 2006 04:23 PM|codeboy|LINK
This probably doesn't help but make sure the connection is open before you execute the reader. I can't tell from your code if its opened before or how that's handled but conceivably if your connection is global or class level you could have a situation where the connection is closed when you try to execute the reader. As i said, this probably isn't it but its the most common reason I recieve this error.
hth,
Visit my Blog
None
0 Points
71 Posts
Re: Operation is not valid due to the current state of the object using the dataReader
Mar 30, 2006 04:01 PM|ASPDavid|LINK
Generally this occurs when your SQL statement returns no values, the reader has nothing to read. Which would also exlplain why it works sometimes, and it doesn't work other times.
None
0 Points
1 Post
Re: Operation is not valid due to the current state of the object using the dataReader
Jun 21, 2010 03:49 AM|Axole|LINK
Hello David!
I have the same problem too. I agree with your statement completely. So whats the best thing to do? I thing catching the error is only option to take. Tell me if you agree.
Thanks
Participant
1246 Points
565 Posts
Re: Operation is not valid due to the current state of the object using the dataReader
Jun 21, 2010 03:58 AM|nideeshm|LINK
data reader requires an open connection since it works on connected architecture.check if the connection is opened. If the rows u r trying to read is locked by someother transaction, i guess oracle might throw this error, Check if u can give nolock hint with select statement.
I would suggest u to use disconnected architecture, usage of datasets. It is easy and simple. It reduces the load on database server. It gets the data and closes the connection automatically. In connected architecture i.e data reader the connection has to be remained open till all ur business logic is completed.
Nideesh.S
Mark as answer, If it helps you.
Participant
981 Points
258 Posts
Re: Operation is not valid due to the current state of the object using the dataReader
Jun 21, 2010 04:14 AM|HerryAtHotmail|LINK
hi.
can you paste whole precedure in which you have written above code?.
thanks.
Participant
1246 Points
565 Posts
Re: Operation is not valid due to the current state of the object using the dataReader
Jun 21, 2010 06:45 AM|nideeshm|LINK
sample code snippet for using dataset,
Dim MyCommand As OracleCommand
Dim sqlStateMent As String="select a_1,a_2 from Table "
MyCommand = New OracleCommand(sqlStatement, myConnection)
Dim ds as DataSet = new DataSet()
Dim da as OracleDataAdapter = new OracleDataAdapter(MyCommand);
da.fill(ds)
'ds.Tables[0] will hold the data
I havent used vb for a long time, check for the syntax.
Nideesh.S
Mark as answer, If it helps you.