Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

 

 

error message

ex.InnerException = {System.Data.SqlClient.SqlException (0x80131904):

 

Die IDUser-Identitätsspalte kann nicht aktualisiert werden.

   at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__108_0(Task`1 result)

   at System.Threading.Tasks.ContinuationResultTaskF...

 

 

In English

Cannot insert explicit value for identity column in table 'Filialen' when IDENTITY_INSERT is set to OFF.

 

Error code

The error occurs when you want to save a record like this one for the aspnetuser plus identity column

ApplicationUser profil = await _dbContext.Users.SingleOrDefaultAsync(u => u.IDUser == IDCurrent_User);

profil.UserName =sUsername;

_dbContext.Update(profil);

await _dbContext.SaveChangesAsync();

 

Solution:

If you have taken a record from the server with dbContext and changed it,

then you can not enter with .update (record) the complete record as changed.

Since the change is already set in EF Entity Framework via dbContext, you only have to transfer the modified fields to the server with .SaveChanges.

The line dbContext.Update (record) must be omitted.

 

Solution Code C # Asp Mvc

            //< check Owner >

            ApplicationUser profil = await _dbContext.Users.SingleOrDefaultAsync(u => u.IDUser == IDCurrent_User);

            if (profil == null)

            {

                return Content("Owner not found");// NotFound();

            }

            //</ check Owner >

 

            string sUsername = Request.Form["Username"];

 

            //----< Edit Data >---- 

            profil.UserName =sUsername;           

            //----</ Edit Data >---- 

 

            //----< Save Data >----           

            try

            {

                //no extra.update recordset !

                await _dbContext.SaveChangesAsync();

            }

            catch (DbUpdateConcurrencyException)

            {

                return Content("Update Error");

            }

            //----</ Save Data >----

 

 

 

 

 

The error occurs with asp applications when inserting an additional identity column in a table such as AspNetUsers.

Since Microsoft already uses a unique PrimaryKey as guid with the id, primarykey id and identity id must not be accessed in writing.

You can only write the changed columns in such tables.

 

Complete solution code in Asp.Net Core MVC

// Postback: User/Edit_Profile

[Authorize]

[HttpPost]

public async Task<IActionResult> Edit_Profile_Postback()

{

// -------------< Edit_Profile() > -------------

//--< Get User ID >--

//internal referenz-Number for tracking in tables

long IDCurrent_User = await UserInfo_Methods.getIDUser_as_Number(this.User, _dbContext);

//--</ Get User ID >--

 

//< check Owner >

ApplicationUser profil = await _dbContext.Users.SingleOrDefaultAsync(u => u.IDUser == IDCurrent_User);

if (profil == null)

{

    return Content("Owner not found");// NotFound();

}

//</ check Owner >

 

string sUsername = Request.Form["Username"];

 

//----< Edit Data >---- 

profil.UserName =sUsername;

//----</ Edit Data >---- 

 

//----< Save Data >----

try

{

    //_dbContext.Users.Attach(profil).Property(x => x.UserName).IsModified = true;

   

    //_dbContext.Update(profil);

    await _dbContext.SaveChangesAsync();

}

catch (DbUpdateConcurrencyException)

{

    return Content("Update Error");

}

//----</ Save Data >----

 

//</ check Owner >

return View("Edit_Profile",profil);

 

// -------------</ Edit_Profile() > -------------

        }

 

Mobile
»
Error: Identity column can not be updated, IDENTITY_INSERT is set to OFF
»
Asp Error: IDENTITY_INSERT OFF when accessing AspNetUsers registry
»
ASP IIS Error: 440.13 Not Found. upload file size is exceeded
»
InvalidOperationException: An exception occurred while reading a database value for property
»
A database operation failed while processing the request. SqlException: Invalid object name
»
InvalidOperationException: No database provider has been configured for this dbContext
»
NullReferenceException: Object reference not set to an instance of an object.
»
InvalidOperationException: The expected type was System.Boolean but the actual value was null.
»
Asp: InvalidOperationException: The model item passed into the ViewDataDictionary is of type
»
InvalidCastException: Unable to cast object of type System.Int32 to type System.Int64

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de