During a save action an entity's update action failed. The entity which failed is enclosed.

Posts   
 
    
qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 29-Sep-2014 14:37:43   

Server Error in '/' Application.

During a save action an entity's update action failed. The entity which failed is enclosed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: SD.LLBLGen.Pro.ORMSupportClasses.ORMConcurrencyException: During a save action an entity's update action failed. The entity which failed is enclosed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

When I try to add a new record, I get an error like the one above.

I am using:

Visual Studio 2012 LLBLGen 3.5 Sql Server 2008 (10.50.1600)

Table1 ( Id identity primary key auto increment, Field1, Field2)

Table2 ( Id identity primary key auto increment, Table1Id, Field3, Field4)

The adding process is done in the following way:

Step 1: Insert a new row to Table1 and get to "Id" {identity} (added to record) Step 2: Insert a new row to Table2 (and use to "Table1.Id" value for Table2.Table1Id field)

This adding process is working our local (sql server 2012 (11.0.3128 )). But It isn't working in live server (sql server 2008 (10.50.1600)). Same database but I get the error.

Because, When I am add a new row to Table1, I can't get to return Id of last last inserted row. It is not return Id{identity} (Step 1). So I think, get the error to step 2...

This problem will be about to scope_identity. But I am not sure.

What Can I do this problem?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Sep-2014 19:36:29   

Which SQL CompatabilityMode are you using (config. setting)?

Please check Compatability Mode

qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 30-Sep-2014 07:57:48   

Walaa wrote:

Which SQL CompatabilityMode are you using (config. setting)?

Please check Compatability Mode

My databases: - Sql Server 2012, Compability level: Sql Server 2008 (100) - Sql Server 2008 R2, Compability level: Sql Server 2008 (100)

In live server database: - Sql Server 2008, Compability level: Sql Server 2008 (100)

I looked to this setting with Sql Server Management Studio. All the same. But it is not working in live server database...

Which should be?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Sep-2014 08:10:34   

About the Compatibility mode that Walaa mentioned, you should be using this for SQLServer 2008:

<add key="SqlServerDQECompatibilityLevel" value="2" />

... and this for SQLServer 2012:

<add key="SqlServerDQECompatibilityLevel" value="6" />

... please check what you have on that. Also make sure that both DBs have identical schema. It might be that you forgot to set autoincremental in production. To be sure generate CREATE scripts on both DBs and compare them.

David Elizondo | LLBLGen Support Team
qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 30-Sep-2014 09:55:30   

daelmo wrote:

About the Compatibility mode that Walaa mentioned, you should be using this for SQLServer 2008:

<add key="SqlServerDQECompatibilityLevel" value="2" />

... and this for SQLServer 2012:

<add key="SqlServerDQECompatibilityLevel" value="6" />

... please check what you have on that. Also make sure that both DBs have identical schema. It might be that you forgot to set autoincremental in production. To be sure generate CREATE scripts on both DBs and compare them.

I added to my web.config this key (<add key="SqlServerDQECompatibilityLevel" value="2" />).. But still does not work.

Scheme in all the same. I checked to tables. Id is primary key and autoincremental in all tables.

It is not working!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Sep-2014 23:11:12   

◦@@IDENTITY with compatibility level SqlServer7, SqlServerCE3x, SqlServerCE35, SqlServerCE40 ◦SCOPE_IDENTITY() with compatibility level SqlServer2000, SqlServer2005, SqlServer2012

Could you please select SCOPE_IDENTITY() on that table after an insert and see if it returns the correct identity.

qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 01-Oct-2014 15:49:43   

Walaa wrote:

◦@@IDENTITY with compatibility level SqlServer7, SqlServerCE3x, SqlServerCE35, SqlServerCE40 ◦SCOPE_IDENTITY() with compatibility level SqlServer2000, SqlServer2005, SqlServer2012

Could you please select SCOPE_IDENTITY() on that table after an insert and see if it returns the correct identity.

DB: sql server 2008 llblgen: 3.5

Code:

I can insert to database in live and local.

static void Main(string[] args) { NuevoLogEntity log = new NuevoLogEntity { TimeStamp = DateTime.Now, LogType = 1, Priority = 1, Description = "Test Log Record" }; log.Save();

        int productDbId = log.Id; _// always returning 0 (from live server)_
        int localDbId = log.Id;  _// generated Id_

    }

Config:

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" /> </configSections> <connectionStrings> <add name="ConnectionString.SQL Server (SqlClient)" connectionString="server=XX.XX.XX.XX;database=DB;uid=USERNAME;pwd=PASSWORD" providerName="sqlserver" /> </connectionStrings> <sqlServerCatalogNameOverwrites> <add key="SqlServerDQECompatibilityLevel" value="2" /> </sqlServerCatalogNameOverwrites> </configuration>

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Oct-2014 21:29:32   

Why are you adding the comp mode setting inside the sqlServerCatalogNameOverwrites tag? It should be inside the appsettings tag.

qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 02-Oct-2014 08:25:41   

Walaa wrote:

Why are you adding the comp mode setting inside the sqlServerCatalogNameOverwrites tag? It should be inside the appsettings tag.

Hi Walaa,

I add to appsetting tag. But It is returning 0..

Code:

    static void Main(string[] args)
    {

        LogEntity log = new LogEntity
        {
            TimeStamp = DateTime.Now,
            LogType = 1,
            Priority = 1,
            Description = "Test Log Record 1"
        };
        log.Save();
        int productDbId = log.Id;

        Console.WriteLine(productDbId.ToString());
        Console.ReadKey();
    }

<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <appSettings> <add key="SqlServerDQECompatibilityLevel" value="2" /> </appSettings> <connectionStrings> <add name="ConnectionString.SQL Server (SqlClient)" connectionString="server=XX.XX.XX.XX;database=DATABASE;uid=USERNAME;pwd=PASSWORD;MultipleActiveResultSets=True" providerName="sqlserver" /> </connectionStrings> </configuration>

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Oct-2014 18:19:32   

Could you please select SCOPE_IDENTITY() on that table after an insert and see if it returns the correct identity.

qwerty
User
Posts: 6
Joined: 29-Sep-2014
# Posted on: 02-Oct-2014 19:46:07   

Walaa wrote:

Could you please select SCOPE_IDENTITY() on that table after an insert and see if it returns the correct identity.

We tried all scenarios. The problem was in on live server database. We installed sql server express 2012. It is working everyting.

Thanks for your help.