Friday, March 9, 2012

NullReferenceException on an already instanciated object in SQL/C#

Hi, I've posted the following message in the .NET C# MSDN newsgroup, but
there really hasn't been the answer/help that I was expecting. Therefore I a
m
trying the thread here.
--
Hello, I have a perplexing situation. I have the following set of code, whic
h
depends on a scheduling library from GravityBox software (Schedule.NET 2005)
.
Nobody in their forums has been able to help me resolve this problem:
scheduleDomainController1.ConnectionString =
"data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
string AccountID = "00000000-0000-0000-0000-000000000000";
try
{
dataSet1 =
scheduleDomainController1.GetScheduleDataSet(AccountID);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
schedule1.DataSource = dataSet1;
schedule1.Bind();
The line above: dataSet1 =
scheduleDomainController1.GetScheduleDataSet(AccountID);
is always raising an exception: NullReferenceException.
"Object reference not set to an instance of an object"
dataSet1 is instanciated/created at runtime as well as
scheduleDomainController1.
I'm miffed here as to why I'm getting this exception. Any clues?
Thanks
MikeI don't know anything about your object, but when using datasets in VB.Net I
often get this same exception. It usually means that either no data was
returned, or there was a database error while retrieving the data.
"eljainc" <eljainc@.discussions.microsoft.com> wrote in message
news:079F346A-ED63-41DC-810B-36B563A6B3C8@.microsoft.com...
> Hi, I've posted the following message in the .NET C# MSDN newsgroup, but
> there really hasn't been the answer/help that I was expecting. Therefore I
am
> trying the thread here.
> --
> Hello, I have a perplexing situation. I have the following set of code,
which
> depends on a scheduling library from GravityBox software (Schedule.NET
2005).
> Nobody in their forums has been able to help me resolve this problem:
> scheduleDomainController1.ConnectionString =
> "data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
> string AccountID = "00000000-0000-0000-0000-000000000000";
> try
> {
> dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message + ex.StackTrace);
> }
> schedule1.DataSource = dataSet1;
> schedule1.Bind();
>
> The line above: dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> is always raising an exception: NullReferenceException.
> "Object reference not set to an instance of an object"
> dataSet1 is instanciated/created at runtime as well as
> scheduleDomainController1.
> I'm miffed here as to why I'm getting this exception. Any clues?
> Thanks
> Mike|||Mike,
Can you post the complete stack trace of that exception? That would
help me determine whether the exception is generated from the current
method or from the GetScheduleDataSet method.
Brian
eljainc wrote:
> Hi, I've posted the following message in the .NET C# MSDN newsgroup, but
> there really hasn't been the answer/help that I was expecting. Therefore I
am
> trying the thread here.
> --
> Hello, I have a perplexing situation. I have the following set of code, wh
ich
> depends on a scheduling library from GravityBox software (Schedule.NET 200
5).
> Nobody in their forums has been able to help me resolve this problem:
> scheduleDomainController1.ConnectionString =
> "data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
> string AccountID = "00000000-0000-0000-0000-000000000000";
> try
> {
> dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message + ex.StackTrace);
> }
> schedule1.DataSource = dataSet1;
> schedule1.Bind();
>
> The line above: dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> is always raising an exception: NullReferenceException.
> "Object reference not set to an instance of an object"
> dataSet1 is instanciated/created at runtime as well as
> scheduleDomainController1.
> I'm miffed here as to why I'm getting this exception. Any clues?
> Thanks
> Mike|||Is this sceduledomaincont1 an instance?
Juz for test
can you add this before the assignment like this?
dataSet1 = new DataSet();
dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
--

No comments:

Post a Comment