executenonquery connection property has not been initialized.

This has bitten me twice now.
Code written below is Microsoft Patterns & Practices Enterprise Library 2.0 Data Access Layer.
Database database = DatabaseFactory.CreateDatabase("Your Connection String Name in Web Config");
string sqlcommand = "Your Stored Procedure Name";
DbCommand databasecommand = database.GetStoredProcCommand(sqlcommand);
database.AddInParameter(databasecommand, "@Status", DbType.String, "Complete");
int i = databasecommand.ExecuteNonQuery();
This looks fairly straight forward. However, if you run it you will get the error, "executenonquery connection property has not been initialized."
The proper way to call ExecuteNonQuery above is

int i = database.ExecuteNonQuery(databasecommand);
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)


Twitter Delicious Facebook Digg Stumbleupon Favorites More