How to set IDENTITY_INSERT as ON?

First of all, I ask the administrator to delete this message: 'How-can-I-do-a-primary-key-in-Autoincrement-in-Vb-net-2008/959787 # 959787' because I ran into a problem with a comment, and when I try to add a comment, the error message is apper: "comment requires 50 reputation - see faq"!

Here I just want to ask about IDENTITY_INSERT, how can I set it to ON in vb.net 2008 this error occurs: http://www.rofof.com/img2/6amojc6.gif

I am very sorry for these problems that I cause.

+4
source share
3 answers

It looks like your Linq to SQL classes are not in sync with your database. You need to update them. If you are using the built-in visual studio designer, delete the table from your DBML and then add it again.

Attributes for primary key columns must have attributes that look like this:

[Column(Storage="_TeacherID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] 
+6
source

If this is what you want to do, you must also provide a table name.

SET IDENTITY_INSERT tablename ON

+1
source

Good,

 SET IDENTITY_INSERT ON 

but it needs to be done with the same connection (without closing the connection) where you execute your request.

By the way, are you sure you want to insert the value in the identity column? Your linq to sql interface may not be updated. If so, you can

  • delete the table from the model and redistribute it, or
  • select in your linq to sql model a field that is personal and set it as

    IsDBGenerated = True

    AutoSync = AutoSync.OnInsert

0
source

Source: https://habr.com/ru/post/1285845/


All Articles