472,362 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,362 software developers and data experts.

SQLTransaction locking up table

Hi All,

I am using a SQLTransaction to insert records into a table. At one
time, there are 5000 or more records to be inserted one by one. It
takes some 20-25 mins for the entire process to run.

Another application accesses the same table.

As long as the insert process within the transaction isn't completed,
the second application is not getting any response from the server. I
even tried to run a SELECT on the table in SQL Query Analyzer while the
insert process was running and it also did not respond till the time
the insert process finished!

Is this normal that a transaction is locking up a table? How do I
overcome it? I am using IsolationLevel.ReadUncommitted for the
transaction.

If I do not run the process within a SQLTransaction, the second process
or running the SELECT in Query Analyzer does not hang.

Thanks,
Sanjeev Mahajan

Jul 23 '05 #1
3 6005
Your description sounds more or less normal - if you have your INSERTs
inside a transaction, then other processes will not be able to see that
data until the transaction commits. Transactions don't always lock the
whole table, but it depends on what you're doing, your volume of data,
your indexes etc.

In any case, 20-25 minutes to insert only 5000 rows sounds extremely
slow - can you insert all the rows at once in a single INSERT, rather
than one by one? You might want to give some more details of exactly
how you're inserting the data (does it come from a cursor, an external
file, a client application etc.), and the DDL for your table - with
more information, someone may be able to suggest an improvement to your
current process.

Simon

Jul 23 '05 #2
[posted and mailed, please reply in news]

(ma*************@gmail.com) writes:
I am using a SQLTransaction to insert records into a table. At one
time, there are 5000 or more records to be inserted one by one. It
takes some 20-25 mins for the entire process to run.

Another application accesses the same table.

As long as the insert process within the transaction isn't completed,
the second application is not getting any response from the server. I
even tried to run a SELECT on the table in SQL Query Analyzer while the
insert process was running and it also did not respond till the time
the insert process finished!

Is this normal that a transaction is locking up a table? How do I
overcome it? I am using IsolationLevel.ReadUncommitted for the
transaction.


Which isolation level you use for the INSERT, does not really matter here.
If another process says "SELECT * FROM tbl" when the INSERT process is
running, that process will be blocked, since it cannot read the newly
inserted but uncommitted. Unless, that is, the SELECT processes uses the
READ UNCOMMITTED isolation level. However, one should be very careful
with using dirty reads. If you don't understand the implications of
dirty reads, you should not play with them.

20-25 minutes for inserting 5000 rows is an awful lot of time. Is there
a trigger on the table? Inserting one-by-one is never effective, but
250 ms seconds per row is extreme.

One thing you could consider is to build an XML string from your
data, and then pass that string to a stored procedure which uses
OPENXML to shred this string. Then you can insert all 5000 rows in
one go. We have been using this in our application, to improve performance
in places where the GUI needs to store a lot of data in the database.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3
The second process accessing the table is blocked on X locks held by the
forst process doing the insert. These can be row, page or table locks.
read uncommitted isolation doesn't take effect for modification like
insert/delete/update. You will have to make the second process to access
the table under read uncommitted so that it doesn't not take any lock, thus
not to be blocked by the insert.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
<ma*************@gmail.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
Hi All,

I am using a SQLTransaction to insert records into a table. At one
time, there are 5000 or more records to be inserted one by one. It
takes some 20-25 mins for the entire process to run.

Another application accesses the same table.

As long as the insert process within the transaction isn't completed,
the second application is not getting any response from the server. I
even tried to run a SELECT on the table in SQL Query Analyzer while the
insert process was running and it also did not respond till the time
the insert process finished!

Is this normal that a transaction is locking up a table? How do I
overcome it? I am using IsolationLevel.ReadUncommitted for the
transaction.

If I do not run the process within a SQLTransaction, the second process
or running the SELECT in Query Analyzer does not hang.

Thanks,
Sanjeev Mahajan

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
2
by: Randall Sell | last post by:
Hello all, Somewhere on these newsgroups I recall reading that SQL Server 6 and prior (when they were married with Sybase) used page locking and not row level locking. Hence you could be locking...
2
by: mahajan.sanjeev | last post by:
I have two SQLConnection objects having the same connection string and two corresponding SQLCommand objects for each connection object. I am using SQLTransaction with the first SQLConnection object...
0
by: mahajan.sanjeev | last post by:
Hi All, I am using a SQLTransaction in a .Net application to insert records into a SQL Server table. At one time, there are 5000 or more records to be inserted one by one. It takes some 20-25...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
5
by: Swami Muthuvelu | last post by:
Hi, I using command builder to generate my insert, update and delete statements..something like, data_adapter = New SqlClient.SqlDataAdapter(SQL, ActiveConnection) command_builder = New...
3
by: Neven Klofutar | last post by:
Hi, I'm trying to retrieve some information from DB using SqlTransaction, but I have a problem. I'm executing some DELETE SQL statements using Transaction. Then later on (because of the lousy...
4
by: perspolis | last post by:
Hi all I have a master-detail tables in sql server. I use SqlTransaction to insert data into both tables. it works well but if I check the "Cascade Delete Related Records" option in it's realtion...
2
by: samuelberthelot | last post by:
Hello, I have a asp.net application in which users can create content and then save everything to a SQLServer2000 database. When they hit the save button on the form here is what I do : Dim...
3
MrMancunian
by: MrMancunian | last post by:
Ok, I'm stuck on a design problem and I need some feedback how to go around it. CASE: Pathologists can request stains on certain tissues. It's possible to request more than one stain a time....
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.