Code ok in DEBUG fails in Release

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a c# function that runs fine in VS.Net when in debug mode; however,
when I switch to Relase mode or compile the app, the function fails with
"object refernce not set".

Here is the whole function:
private void GetETCStatus()
{
oConn.Open();
szSQL = "SELECT ParamValue FROM Params WHERE Param =
'ETCsAvailable'";
cmd.CommandType = CommandType.Text;
cmd.CommandText = szSQL;
object o = cmd.ExecuteScalar();
szTemp = o.ToString().ToUpper();
if (szTemp == "YES")
{
this.cmdETCs.Text = "&Disable ETCs";
bETCsAvailable = true;
}
else
{
this.cmdETCs.Text = "&Enable ETCs";
bETCsAvailable = false;
}
this.Refresh();
oConn.Close();
}

the line that fails is:
szTemp = o.ToString().ToUpper();

All I'm trying to do is retrieve one scalar value from the SQL database. I
don't need a dataset for this.

Can someone explain why it works in DEBUG and not in release? (Makes it very
difficult to troubleshoot.)

In lieu of that, can someone show me a better way to accomplish what I'm
trying to do here?


Thanks,
John
 
Is this the only things that change ? If you don't run the debug and the
release code on the same datasource, it could be just that the line is
missing from the Params table...
 
Patrice,

Thanks for your response. I think you're right. I was looking at two
different data sources based upon whether it was production or testing.
However, it should have been the other way aroound because the datasource for
debug did not have the record, yet teh datasource for release did.

I think what happened is I got my command line params confused in VS.Net.
In 6.0 there was no difference between debug and release and I did not
realize there was a seperate command line configuration for debug/release in
VS.Net.


Always learning.

Thanks again.
 
Back
Top