tags:

views:

23

answers:

3

I am getting error ExecuteReader: Connection property has not been initialized. below is the code i am using.

SqlDataReader oReader = new SqlDataReader();
string sSQL = @"
    WITH TAB_CTE AS (
    SELECT fbominum, fbompart, fparinum, flevel, fsono
    FROM sodbom
    WHERE  fbompart= @fbompart and fsono = @fsono
    UNION ALL
    SELECT e.fbominum, e.fbompart, e.fparinum,   e.flevel, e.fsono
    FROM sodbom e 
    INNER JOIN TAB_CTE ecte ON ecte.fbominum = e.fparinum  where e.fsono = @fsono
    )
    SELECT *
    FROM TAB_CTE where fbompart <> @fbompart 
    ";
SqlCommand oCommand = new SqlCommand(sSQL, this._connection);
oCommand.CommandType = System.Data.CommandType.Text;
oCommand.Parameters.Add("@fbompart", ItemSODBOM.fbompart);
oCommand.Parameters.Add("@fsono", ItemSODBOM.SONO);
oReader = oCommand.ExecuteReader();//Here I am getting error
+1  A: 

this._connection must be un-initialized.

You would need to post more of the relevant code for us to be sure.

Justin Niessner
this._connection we are using n number of times in our code, only this is the place i am getting error
Pradeep
@Pradeep - It could still be the case that the other uses are after the object is initialized and yours is the only case that is trying to use it prior to initialization.
Justin Niessner
yes i got, you were right
Pradeep
+1  A: 

My guess is that this._connection is null... have you verified that that's not the case?

The documentation doesn't say that the constructor will throw an exception if the connection is null, so my guess is it allows you to pass in null, hoping that you'll set the Command property explicitly later if so.

Jon Skeet
A: 

You need to check the Connection object and need to make sure that its ConnectionString property is NOT NULL.

Nadeem