Last post Jun 21, 2010 06:45 AM by nideeshm
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:
Dim MyCommand As OracleCommand
Dim sqlStateMent As String="select a_1,a_2 from Table "
Dim Reader As OracleDataReader
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.
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.
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.
Jun 21, 2010 03:49 AM|Axole|LINK
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.
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.
Jun 21, 2010 04:14 AM|HerryAtHotmail|LINK
can you paste whole precedure in which you have written above code?.
Jun 21, 2010 06:45 AM|nideeshm|LINK
sample code snippet for using dataset,
MyCommand = New OracleCommand(sqlStatement, myConnection)
Dim ds as DataSet = new DataSet()
Dim da as OracleDataAdapter = new OracleDataAdapter(MyCommand);
'ds.Tables will hold the data
I havent used vb for a long time, check for the syntax.