views:

818

answers:

3

in the first I ask the admin to remove this post: 'how-can-i-make-a-primary-key-as-autoincrement-in-vb-net-2008/959787#959787' because I am facing a problem with comment and when I try to add comment the error message is apper: "commenting requires 50 reputation -- see faq" !

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

I am so sorry for this problems which I cause it.

+4  A: 

Sounds like your Linq to SQL classes are out of 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.

The attributes for the primary key columns should have attributes that look like this:

[Column(Storage="_TeacherID", 
 AutoSync=AutoSync.OnInsert, 
 DbType="Int NOT NULL IDENTITY", 
 IsPrimaryKey=true, 
 IsDbGenerated=true)]
Keltex
thank you .
turki2009
Great! This is exactly what I needed, using Visual Studio :)
BennySkogberg
A: 

Well using,

SET IDENTITY_INSERT ON

but it has to be done with the same connection (without closing the connection) where you perform your query.

By the way, are you sure you want to insert a value in identity column? Maybe your linq to sql mapping is not up to date. If that is the situation, you can

  • drop the table from the model and reallocate it, or
  • select in your linq to sql model the field wich is identity and set it's properties as

    IsDBGenerated = True

    AutoSync = AutoSync.OnInsert

eKek0
thank you .
turki2009
A: 

In case it is what you want to do, You must also include the table name.

SET IDENTITY_INSERT tablename ON

Mike L