AFAIK, SQL Server locks a table as soon as it inserts a record into it and 
only releases it upon commit/rollback.

RP

On Tuesday, June 3, 2014 4:09:27 PM UTC+1, Lee Timmins wrote:
>
> I have a particular task which takes a minute or so to execute. I have 
> noticed that whilst the task is running the table that it is trying to add 
> data to is being locked and therefore additional users are getting errors.
>
> To help me investigate a way to solve this I have added the following code:
>
> using(var session = sessionFactory.OpenSession()) 
> using(var tx = session.BeginTransaction())
> { 
>     for (var i = 0; i < 10; i++)
>     {
>         session.SaveOrUpdate(new Log("Test: " + i));
>     }
> }
>
> I set a breakpoint after it adds to the log table and found that I cannot 
> access the log table (using SQL Server Management Studio) once there are 
> pending changes on the table.
>
> Now If I want to commit per item I would add a tx.Commit() within the for 
> loop. This seemed to remove the locking issue but what if I only wanted to 
> commit once all the inserts have been made? I tried doing a Flush within 
> the loop (instead of a commit) and a commit at the end but then I got the 
> locking issue again.
>
> I'd appreciate it if someone could clarify what's going on here and how I 
> could solve this. Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to