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.
On Thu, 23 Sep 2004 10:59:49 -0600, Bradley Plett <plettb@hotmail.com>
[quoted text, click to view] wrote:
>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.