473,769 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6090
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****@sommarsk og.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******** ************@g4 9g2000cwa.googl egroups.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
5068
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 access them and automatically they can not continue their works. I have tried using the following code, but it does not work. I always got the error :
2
6875
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 a lot more records then what you think when doing an UPDATE or INSERT SQL. Now I notice that SQL Server 7 and 2000 claim to use row level locking. (As you can see, I have been out of the SQL arena for some time). So what I'd like to know if...
2
2059
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 but the second SQLConnection object does not have any SQLTransaction object. I am inserting some data using the two command objects. The problem happens when I try to do a rollback on the SQLTransaction object. The rollback happens only before...
0
1081
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 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,
2
2769
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 information into three separate tables (all in a single aspx page -- without using stored procedures, yet). The first SQL Statement accepts the persons most detailed information, like name, address, phone, etc and inserts the single record into...
5
451
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 SqlClient.SqlCommandBuilder (data_adapter)
3
1297
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 project) I need to read the same information from DB that is beeing deleted using the same transaction. Is it possible to delete data, and read the same data in one SqlTransaction, or that Transaction cannot read the data anymore even if Commit()...
4
2901
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 in sql server my SqlTransaction dosen't work and get timeout error.. please help me thanks in advance
2
4616
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 conn As SqlClient.SqlConnection = New SqlClient.SqlConnection( myconnectionstring ) Dim tx As SqlClient.SqlTransaction conn.Open()
3
3134
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. The program where they make these requests (which is third-party software) creates an XML-file for one stain. So, if two stains are requested on one piece of tissue, it will create two XML-files. The program I'm writing needs to parse those XML-files,...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.