Connection is closed for ExecuteNonQuery

Topics: Data Access Application Block
Nov 8, 2012 at 3:47 PM


I am using Net Framework 4 and Enterprise Liblary 5

After getting of instance 

database =EnterpriseLibraryContainer.Current.GetInstance<Database>("");

I try to execute a stored procedure

DbCommandinsertCommand = database.GetStoredProcCommand(spName, parameterValues);


An error “Invalid operation. Connection is closed” appears

I can workaround it by adding the next rows of code before calling ‘ExecuteNonQuery’

DbConnection connection = database.CreateConnection();

insertCommand.Connection = connection;


I think it is not a fine solution. In all examples it works without any workarrounding.

What is the problem?

Nov 8, 2012 at 5:07 PM

The Enterprise Library ExecuteNonQuery method will open a new connection so you should not have to manually open .  Can you provide more information?  e.g. the full stack trace, what database you are using, etc.  

Randy Levy
Enterprise Library support engineer 

Oct 30, 2013 at 10:12 AM
Any solution about it?