I need to block a table from being accessed by any other process unless my current operation(usually a INSERT or an UPDATE) is completed, Is there a way to lock and unlock sql server tables from .net code without using stored procedures, i need these to avoid business rules based duplicate records from being entered into the table.
Share
You an use a hint
insert into table with (tablock) (colx) values (‘newValuex’);
If valuex is a primary key or has a unique constraint then it will be enforced.
But you don’t need a tabloc to enforce that constraint.
If you have multiple statements then you can wrap them in a transaction.