Print Page | Close Window

How to do Identity Insert with the PM.

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=664
Printed Date: 11-Jun-2026 at 9:18am


Topic: How to do Identity Insert with the PM.
Posted By: Quigrim
Subject: How to do Identity Insert with the PM.
Date Posted: 25-Jan-2008 at 12:04am
On SQL Server you can insert a specific value into an identity column by just running the following statement first:
SET IDENTITY_INSERT <tablename> ON

I need to do the same thing adding an entity with DevForce.
I haven't been able to find out any information on how to do this.
Would greatly appreciate some assistance on this?

Thanx much.
Jacques



Replies:
Posted By: davidklitzke
Date Posted: 25-Jan-2008 at 1:16pm

I am not quite sure why you have this requirement.  It might help if I knew this.  Do you have a requirement that you be able to insert very specific values, or do you simply need to guarantee that the number you insert on the client is not going to be changed by the database?  If it is the latter, DevForce already guarantees this behavior.

This is what DevForce Help says:

Sql Server Identity Id Generation

The default DevForce processing for SQL Server tables with an identity column uses two SQL Server features which require that the connected user have elevated privileges:

·         DBCC CHECKIDENT, so we can re-set the curren seed for the next identity value.

·         SET IDENTITY_INSERT, so we can specify the Identity column value on insert.

When DevForce issues those commands, it must be logged in either as the owner of the tables or as a member of the sysadmin, db_owner or db_ddladmin roles.

This shouldn’t be an issue in an n-tier deployment where the DevForce process issuing these commands is running in a secure environment on a host machine.

Two-tier (“Client/Server”) applications may be ok too, especially if they execute on a secure LAN and the connection string specifies Windows authentication.

Some applications don’t fit these criteria. They are two-tier and n-tier, for some reason, is not a current option. Perhaps they can’t use Windows authentication and must specify a username and password in the connection string. No one wants connection credentials with administrator rights floating about.

Perhaps the application can switch from Identity Ids to a table-drive custom id design. That won’t be an option if there are legacy applications referencing the same data.


 Related Topics
mk:@MSITStore:C:\Program%20Files\IdeaBlade%20DevForce\Documentation\IdeaBlade%20DevForce%20Consolidated%20Help.chm::/2/_408.htm - - Identity Id Generation Via Stored Procedure

Note that our SqlServerIdentityIdGenerator doesn’t allow you to use a “specific” value, just the “next” one.  You can implement a custom IIdentityIdGenerator and possibly accomplish the “specific” value part.  But when the generator is called to map temp to real it only knows about temp ids, you’d have to use the EntityColumn in the temp id to get to the Entity.  The mapping also is done for all records to be inserted – if user wanted it done one-by-one they’d have to do a ForceIdFixup.  So, I’d say potentially doable with a custom implementation, depending on user’s requirements.

If the IIdentityIdGenerator doesn’t work, then RPC might work, or anything where they’d use the AdoHelper to directly work with the connection and command objects.

 



Posted By: Quigrim
Date Posted: 27-Jan-2008 at 12:01pm
Hi David. Thank you for the response.
 
The reason for this is that I have a legacy system and DB and have another copy of that DB running the same Entity Model.
DB 1 allocates those ID's with it's identity column, but I need to populate those same specific ID's into DB2's identity column.
The catch comes in that I'm running the same model against both DB's. I could have run a different model against DB2 and removed that columns identity specification on DB2, but for various other reasons we decided on the same model for both DBs.
 
Before I got your reply, I just implemented a passthrough query that uses standard SQL to insert into that table after having turned on IDENTITY_INSERT. This works, and due to deadlines on the project it'll have to stay like that for now, but I'd like to come up with a more elegant solution to this problem some time.
 
Jacques



Print Page | Close Window