Ok this one has me stumped. Everything looks right, but for whatever reason
the DataReader keeps telling me not set to an instance of an object. When I
step through the code, it runs the line

SqlDataReader mySqlReader;

However I can see in the watch value that the mySqlReader is set to an
undefined value

When it gets to the mySqlReader = sc.ExecuteReader() command I get the not
set error

Anyone have any thoughts?

Code below
<code>

int [] results;

results = new int[5];


SqlDataReader mySqlReader;

sc.Connection = sqlConn;

sc.CommandTimeout = 450;

try

{

sqlConn.Open();

mySqlReader = sc.ExecuteReader();

while(mySqlReader.Read())



</code>

Re: SqlDataReader by Miha

Miha
Thu Oct 27 07:24:33 CDT 2005

Hi Justin,

Have you forgot to set CommandText?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Justin Lazanowski" <justin@nospam.southeastmilk.org> wrote in message
news:eYavYBv2FHA.896@TK2MSFTNGP09.phx.gbl...
>
>
> Ok this one has me stumped. Everything looks right, but for whatever
> reason the DataReader keeps telling me not set to an instance of an
> object. When I step through the code, it runs the line
>
> SqlDataReader mySqlReader;
>
> However I can see in the watch value that the mySqlReader is set to an
> undefined value
>
> When it gets to the mySqlReader = sc.ExecuteReader() command I get the not
> set error
>
> Anyone have any thoughts?
>
> Code below
> <code>
>
> int [] results;
>
> results = new int[5];
>
>
> SqlDataReader mySqlReader;
>
> sc.Connection = sqlConn;
>
> sc.CommandTimeout = 450;
>
> try
>
> {
>
> sqlConn.Open();
>
> mySqlReader = sc.ExecuteReader();
>
> while(mySqlReader.Read())
>
>
>
> </code>
>
>



Re: SqlDataReader by Justin

Justin
Thu Oct 27 07:39:36 CDT 2005



No the sc is a SQL command that is set in the calling function.

All the properties are set, and as stated in the previous message, when I
step through the code after it runs the the SqlDataReader mySqlReader; the
value is still set as undefined.

That is why I am so confused.

Justin


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:O3mokFv2FHA.2600@tk2msftngp13.phx.gbl...
> Hi Justin,
>
> Have you forgot to set CommandText?
>
> --
> Miha Markic [MVP C#]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> "Justin Lazanowski" <justin@nospam.southeastmilk.org> wrote in message
> news:eYavYBv2FHA.896@TK2MSFTNGP09.phx.gbl...
>>
>>
>> Ok this one has me stumped. Everything looks right, but for whatever
>> reason the DataReader keeps telling me not set to an instance of an
>> object. When I step through the code, it runs the line
>>
>> SqlDataReader mySqlReader;
>>
>> However I can see in the watch value that the mySqlReader is set to an
>> undefined value
>>
>> When it gets to the mySqlReader = sc.ExecuteReader() command I get the
>> not set error
>>
>> Anyone have any thoughts?
>>
>> Code below
>> <code>
>>
>> int [] results;
>>
>> results = new int[5];
>>
>>
>> SqlDataReader mySqlReader;
>>
>> sc.Connection = sqlConn;
>>
>> sc.CommandTimeout = 450;
>>
>> try
>>
>> {
>>
>> sqlConn.Open();
>>
>> mySqlReader = sc.ExecuteReader();
>>
>> while(mySqlReader.Read())
>>
>>
>>
>> </code>
>>
>>
>
>



Re: SqlDataReader by Justin

Justin
Thu Oct 27 09:16:32 CDT 2005

Ok, I found the error.

Apperently the SP was returning a raiseerror and when I try and assign any
value or for that matter even run .ExecuteReader() it throws a general
Exception.

So this change the scope of the question a little bit

I have the .ExecuteReader() in a try catch finally block.

So How do I get it to throw the exception here as opposed to throwing a
gneral exeception that breaks the application?

I appreciate any help

The entire method appears below

System.Data.SqlClient.SqlDataReader dr;

int [] results;

results = new int[5];



sc.Connection = sqlConn;

sc.CommandTimeout = 450;

try

{

sqlConn.Open();


dr = sc.ExecuteReader();



while(dr.Read())

{

try

{

for (int i=0; i< dr.FieldCount; i++)

{

results[i] = int.Parse(dr[i].ToString());

results[i] = int.Parse(dr[i].ToString());

results[i] = int.Parse(dr[i].ToString());

}

}

catch(System.Data.SqlClient.SqlException ex)

{

error = ex.ToString();

}

catch(System.Exception ex)

{

error = ex.ToString();

}



}

dr.Close();



}

catch (System.Data.SqlClient.SqlException ex)

{

error = ex.Message.ToString();

return null;

}

catch (System.Exception ex)

{

error = ex.Message.ToString();

return null;

}

finally

{

sqlConn.Close();


}

error = string.Empty;


return results;


}

"Justin Lazanowski" <justin@nospam.southeastmilk.org> wrote in message
news:eYavYBv2FHA.896@TK2MSFTNGP09.phx.gbl...
>
>
> Ok this one has me stumped. Everything looks right, but for whatever
> reason the DataReader keeps telling me not set to an instance of an
> object. When I step through the code, it runs the line
>
> SqlDataReader mySqlReader;
>
> However I can see in the watch value that the mySqlReader is set to an
> undefined value
>
> When it gets to the mySqlReader = sc.ExecuteReader() command I get the not
> set error
>
> Anyone have any thoughts?
>
> Code below
> <code>
>
> int [] results;
>
> results = new int[5];
>
>
> SqlDataReader mySqlReader;
>
> sc.Connection = sqlConn;
>
> sc.CommandTimeout = 450;
>
> try
>
> {
>
> sqlConn.Open();
>
> mySqlReader = sc.ExecuteReader();
>
> while(mySqlReader.Read())
>
>
>
> </code>
>
>