Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Manual assignment of Primary Key
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00811534
Message ID:
00811708
Views:
13
The lock is done via a Stored Procedure in SQL Server. It is wrapped around the update statement and is immediately unlocked after a successful lock. This was an option if you didn't want to use Identity.

You can create a custom DataAccess class that contains your Stored Procedure call for the InsertCommand of the DataAdapter used to perform the update. The Developer's Guide has a page called "Creating Custom Data Access Classes" that steps you through the process.

>You shouldn't lock a table or record across multiple SQL calls, that was the Foxpro way of assigning PK. My main question here is which method in the framework can I override so I can call a SP instead of using the CommandBuilder to perform the INSERT.
>
>There is another way I can think of which is retrieve the max PK, then attempt the insert with a try catch block, retry the insert with the next number for a number of times. Again, where should I add this code?
>
>Stephen
>
>
>>How you get at the next primary key is a separate issue from MMF. Some developers us an ID table that contains the next id to use for each table. The table is locked while the next key is extracted to avoid any concurrency issues. If you find the next id from the actual table, you will need to manually deal with concurrency issues.
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform