throwing Invalid operation exception

Topics: Data Access Application Block
Aug 27, 2010 at 9:39 PM
Hi all,
I am trying to use the following code to execute a procedure. 
its thorwing an exception saying connection object should not be null, 
but in the documentation its said that DAAB will manage the connection. 
or do i need to create a connection and assign it to the command and should i need to open and close the connection.
here is the code that i used
DbCommand dbcom = Context.CommonDb.GetStoredProcCommand("sp_add_tmp");
Context.CommonDb.AddInParameter(dbcom, "log", DbType.Int32, input.og);
Context.CommonDb.AddInParameter(dbcom, "id_job", DbType.String, input.id_job);
Context.CommonDb.AddInParameter(dbcom, "cd_status", DbType.String, input.cd_status);
Context.CommonDb.AddInParameter(dbcom, "package_name", DbType.String, input.package_name);
Context.CommonDb.AddInParameter(dbcom, "procedure_name", DbType.String, input.procedure_name);
Context.CommonDb.AddOutParameter(dbcom, "msg", DbType.String, 10);
int result = dbcom.ExecuteNonQuery();

Aug 31, 2010 at 3:47 AM

Hi sathishnb4u,

Yes DAAB should manage the connection. You're getting the "connection object should not be null" exception because it is the DBCommand object (dbcom) which you assigned to execute the sql command instead of your Database object (I assume Context.CommonDb is your Database object). You should use Context.CommonDb.ExecuteNonQuery(dbcom); instead. HTH.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.