Very strange ExecuteScalar bug/problem

B

Bradley Plett

I'm sorry about the cross-post, but this one has me completely
baffled. I don't know if the problem is with Oracle, .NET, Visual
Studio, my machine....

I have some very simple code (see below) in which I use a method
called ExecuteScalar. It works like a charm when run in debug mode in
VS. However, the compiled executable fails on that method.

The code snippet is as follows (sorry about the line-wrap):
--------------------------------------------------
Dim mobjOracleConnection As New
OracleConnection(mstrConnectionString)
Dim lobjCmd As New OracleCommand("SELECT MAX(TRANS_DT) AS LAST_DATE
FROM METERED_VOLUMES", mobjOracleConnection)
mobjOracleConnection.Open()
lobjCmd.ExecuteScalar
--------------------------------------------------
With various debugging statements, I have confirmed that it is
definitely the "lobjCmd.ExecuteScalar" statement that fails. If I use
any other method to get the result (e.g. "ExecuteReader") it works.
When run in the debugger, "ExecuteScalar" works like a charm. When
the compiled executable is run, it produces the following exception:
--------------------------------------------------
Exception: System.InvalidOperationException: Operation is not valid
due to the current state of the object.
at Oracle.DataAccess.Client.OracleDataReader.Read()
at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
at ....
--------------------------------------------------
Another odd thing is that if I move the connection "Open" before the
"New OracleCommand", it still runs fine in debug but produces a
different exception when the executable runs:
--------------------------------------------------
Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
at ....
--------------------------------------------------

Why the difference between debug and runtime?

Another piece of the puzzle is that the same compiled executable seems
to work fine on another machine!?! I've done as much version checking
as I can think of, and the machines seem to be configured identically.

Any thoughts?

Thanks!
Brad.
 
G

Guest

Brad,

I almost exactly the same problem (object reference not set on an
ExecuteScalar) when I upgraded to VS 2003. I found that because I had
Microsoft Oracle .NET Data Provider installed that this conflicted with the
Oracle provider DLLs that are part of VS 2003 (.NET 1.1).

After I uninstalled the MS Oracle Data Provider everything was fine.

sh-
 
B

Bradley Plett

Well, I've found something that will get my code running again. It's
not really a solution nor a workaround, but.... It's either a bug or
a lack of understanding on my part.

A few days ago I was debugging a security problem I was having. I had
run "caspol -s off". When I ran "caspol -s on", everything started
working again. This makes practically no sense to me. Why would
having security turned OFF cause something to FAIL, and security
turned ON allow it to succeed? Why would security cause this failure
at "ExecuteScalar" rather than when the object is instantiated? I can
understand a failure at that point if security were too TIGHT, but too
LOOSE? Why would my debug session not be affected by these security
settings? I admit that I find .NET security complicated to say the
least, and this one makes it seem like even more of a mystery!

Anyway, my code is working for now, so I guess I'll be satisfied with
that. Microsoft: I still think this is a bug. If it's not, could
you please provide me/us with an easy-to-use tool that would help me
debug my security issues? If such a tool already exists, please
inform me.

Thanks!
Brad.
 
B

Bradley Plett

I wonder if that's part of my problem. Is there an easy way to
uninstall ONLY the Microsoft Oracle .NET Provider?

Anyway, I've found a workaround that will get me through for now.
Check my other post if you're interested.

Thanks!
Brad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top