ExecuteActionQuery - No Connection present. Cannot execute command.

Posts   
 
    
CowHills
User
Posts: 47
Joined: 14-Mar-2007
# Posted on: 28-Nov-2012 17:16:57   

Hi,

I'm having some trouble while using the ExecuteActionQuery. I'm trying to set to SET IDENTITY_INSERT [CustomerInfo] ON but I'm getting the error "No Connection Present" which is strange because a normal insert further in the code is working fine.

What is the reason for this error (What am I doing wrong) ?

OS: Win7 Framework: C# .NET 3.5 DB: SQL 2008 LLBL version 2.0

Following code executed:

StringBuilder queryBuilder = new StringBuilder(); queryBuilder.Append(string.Format("USE {0} ", localDataAdapter.CatalogNameToUse)); queryBuilder.Append(string.Format("SET IDENTITY_INSERT [{0}] ON ", "CustomerInfo")); queryBuilder.AppendLine("");

SqlCommand commandToUse = new SqlCommand(queryBuilder.ToString()); commandToUse.CommandType = CommandType.Text;

localDataAdapter.ExecuteActionQuery(new ActionQuery(commandToUse));

Cheers, Andre

NMackay
User
Posts: 138
Joined: 31-Oct-2011
# Posted on: 28-Nov-2012 18:28:13   

Andre,

Think you have to use ActionQuery for the command but I might be wrong smile


var command= adapter.GetDbProviderFactoryInstance().CreateCommand();
command.CommandText = "drop database master"; // kidding
int res = adapter.ExecuteActionQuery(new ActionQuery(command));

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Nov-2012 03:08:36   

I think this is the cause, and the possible solution (subclass the DataAccessAdapter and create a method to return the active connection: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7165

BTW, you mentioned that you are using LLBLGen v2. If so, we encourage you to upgrade to a newer version, at least v2.6, as v2 is very old.

David Elizondo | LLBLGen Support Team
CowHills
User
Posts: 47
Joined: 14-Mar-2007
# Posted on: 29-Nov-2012 08:21:50   

Thanks for you quick response. I've done as suggested and the ExecuteActionQuery works as expected but now I'm get an error while inserting a record:

Explicit value must be specified for identity column in table 'CustomerInfo' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.

This error looks correct but I'm sure I'm passing all the correct values. For some reason the LLBL framework thinks it doesn't have worry about the Identity column. But that is exactly what I want to insert.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Nov-2012 20:57:20   

We don't insert a value for a sequenced field. You should create another entity type for the import stuff.

NMackay
User
Posts: 138
Joined: 31-Oct-2011
# Posted on: 30-Nov-2012 10:39:54   

CowHills wrote:

Thanks for you quick response. I've done as suggested and the ExecuteActionQuery works as expected but now I'm get an error while inserting a record:

Explicit value must be specified for identity column in table 'CustomerInfo' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.

This error looks correct but I'm sure I'm passing all the correct values. For some reason the LLBL framework thinks it doesn't have worry about the Identity column. But that is exactly what I want to insert.

You'd be better using a stored procedure to to this if possible IMO and map it to the ORM layer and call it, we tend to leave this kind to TSQL to SP's where needed and do the usual CRUD, queries etc with the ORM layer.