473,796 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ExecuteReader Blocks Inserts on a Table

I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through the
rows, writing them out to a file. This takes about 5 minutes until I close
the reader.

Whilst this is going on, I have another application that is trying to insert
rows into the table. Normally, the inserts happen straight away, but when
the reader is open each insert takes a very long time to complete.

I realise that this is not an unreasonable thing to happen, given that I am
trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select statement,
and even if they were (which they won't), I wouldn't want them included in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles
Jun 27 '08 #1
18 1698
Charles,

Are the 2 applications on the same machine or different machines?

Is the database server on a different machine than the applications?

Kerry Moorman
"Charles Law" wrote:
I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through the
rows, writing them out to a file. This takes about 5 minutes until I close
the reader.

Whilst this is going on, I have another application that is trying to insert
rows into the table. Normally, the inserts happen straight away, but when
the reader is open each insert takes a very long time to complete.

I realise that this is not an unreasonable thing to happen, given that I am
trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select statement,
and even if they were (which they won't), I wouldn't want them included in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles
Jun 27 '08 #2
Charles,

You are by the way not using transaction locking, because then this is the
normal behaviour.

Cor

"Charles Law" <bl***@nowhere. comschreef in bericht
news:Om******** ******@TK2MSFTN GP06.phx.gbl...
>I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through
the rows, writing them out to a file. This takes about 5 minutes until I
close the reader.

Whilst this is going on, I have another application that is trying to
insert rows into the table. Normally, the inserts happen straight away,
but when the reader is open each insert takes a very long time to
complete.

I realise that this is not an unreasonable thing to happen, given that I
am trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select statement,
and even if they were (which they won't), I wouldn't want them included in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles

Jun 27 '08 #3
On Thu, 19 Jun 2008 02:17:57 +0100, "Charles Law" <bl***@nowhere. com>
wrote:
>I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through the
rows, writing them out to a file. This takes about 5 minutes until I close
the reader.

Whilst this is going on, I have another application that is trying to insert
rows into the table. Normally, the inserts happen straight away, but when
the reader is open each insert takes a very long time to complete.

I realise that this is not an unreasonable thing to happen, given that I am
trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select statement,
and even if they were (which they won't), I wouldn't want them included in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles
You might take a look at the Transact-SQL statement SET TRANSACTION
ISOLATION LEVEL.
Jun 27 '08 #4
If the SELECT limits itself using a WHERE clause to rows which aren't in the inserted set, then you
have a chance to have the SELECT not blocked by your INSERTs. But that also depends on what
execution plan you get. If SQL Server drive the SELECT using an index which is on something that can
be used to exclude the rows to INSERT then you shouldn't see this blocking. However, considering you
return so many rows, you need to carefully evaluate your indexing strategy as well as your SELECT
query to make this happen.

Other options include Snapshot isolation and the READPAST optimizer hint. Those are well documented
in Books Online.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Charles Law" <bl***@nowhere. comwrote in message news:Om******** ******@TK2MSFTN GP06.phx.gbl...
>I have a sproc that returns data from a table using a simple SELECT. There are quite a few rows
returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through the rows, writing them
out to a file. This takes about 5 minutes until I close the reader.

Whilst this is going on, I have another application that is trying to insert rows into the table.
Normally, the inserts happen straight away, but when the reader is open each insert takes a very
long time to complete.

I realise that this is not an unreasonable thing to happen, given that I am trying to write to the
table whilst reading from it, but the rows being written will never be included in the WHERE
clause in my select statement, and even if they were (which they won't), I wouldn't want them
included in the selected rows.

Is there a way to read rows so that inserts can still occur without blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles

Jun 27 '08 #5
Hi Kerry

The two applications are on different machines, connected by a fairly slow
link, which is why it takes so long to iterate through the rows returned by
the reader. The database server is clustered on another machine, which is on
a Gb link to the second application, but the first (reader) application is
at the other end of the slow connection.

I could run both on the same machine, but then I would have to transfer the
resulting file over the slow link, and that would take longer in real time.

Charles
"Kerry Moorman" <Ke**********@d iscussions.micr osoft.comwrote in message
news:6A******** *************** ***********@mic rosoft.com...
Charles,

Are the 2 applications on the same machine or different machines?

Is the database server on a different machine than the applications?

Kerry Moorman
"Charles Law" wrote:
>I have a sproc that returns data from a table using a simple SELECT.
There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through
the
rows, writing them out to a file. This takes about 5 minutes until I
close
the reader.

Whilst this is going on, I have another application that is trying to
insert
rows into the table. Normally, the inserts happen straight away, but when
the reader is open each insert takes a very long time to complete.

I realise that this is not an unreasonable thing to happen, given that I
am
trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select
statement,
and even if they were (which they won't), I wouldn't want them included
in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles

Jun 27 '08 #6
Hi Cor

No, I'm not explicitly using transaction locking. I thought, therefore, that
the reader would use row level locking, but if it is, it is still causing
some kind of locking problem.

Charles
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:1E******** *************** ***********@mic rosoft.com...
Charles,

You are by the way not using transaction locking, because then this is the
normal behaviour.

Cor

"Charles Law" <bl***@nowhere. comschreef in bericht
news:Om******** ******@TK2MSFTN GP06.phx.gbl...
>>I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through
the rows, writing them out to a file. This takes about 5 minutes until I
close the reader.

Whilst this is going on, I have another application that is trying to
insert rows into the table. Normally, the inserts happen straight away,
but when the reader is open each insert takes a very long time to
complete.

I realise that this is not an unreasonable thing to happen, given that I
am trying to write to the table whilst reading from it, but the rows
being written will never be included in the WHERE clause in my select
statement, and even if they were (which they won't), I wouldn't want them
included in the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles


Jun 27 '08 #7
Hi Jack

I did read up about this, but it suggested that the default is row level
locking, which seemed to be the one I'd want anyway, so I haven't attempted
to change it. I have just looked again, and I see there is more to this than
I first thought, so I will read up.

Cheers

Charles
"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:55******** *************** *********@4ax.c om...
On Thu, 19 Jun 2008 02:17:57 +0100, "Charles Law" <bl***@nowhere. com>
wrote:
>>I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through
the
rows, writing them out to a file. This takes about 5 minutes until I close
the reader.

Whilst this is going on, I have another application that is trying to
insert
rows into the table. Normally, the inserts happen straight away, but when
the reader is open each insert takes a very long time to complete.

I realise that this is not an unreasonable thing to happen, given that I
am
trying to write to the table whilst reading from it, but the rows being
written will never be included in the WHERE clause in my select statement,
and even if they were (which they won't), I wouldn't want them included in
the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles

You might take a look at the Transact-SQL statement SET TRANSACTION
ISOLATION LEVEL.

Jun 27 '08 #8
Hi Tibor

Thanks for the reply. I hadn't thought about the indexing issue. I will add
these to my reading list.

Cheers

Charles
"Tibor Karaszi" <ti************ *************** @hotmail.nomail .comwrote in
message news:FC******** *************** ***********@mic rosoft.com...
If the SELECT limits itself using a WHERE clause to rows which aren't in
the inserted set, then you have a chance to have the SELECT not blocked by
your INSERTs. But that also depends on what execution plan you get. If SQL
Server drive the SELECT using an index which is on something that can be
used to exclude the rows to INSERT then you shouldn't see this blocking.
However, considering you return so many rows, you need to carefully
evaluate your indexing strategy as well as your SELECT query to make this
happen.

Other options include Snapshot isolation and the READPAST optimizer hint.
Those are well documented in Books Online.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Charles Law" <bl***@nowhere. comwrote in message
news:Om******** ******@TK2MSFTN GP06.phx.gbl...
>>I have a sproc that returns data from a table using a simple SELECT. There
are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate through
the rows, writing them out to a file. This takes about 5 minutes until I
close the reader.

Whilst this is going on, I have another application that is trying to
insert rows into the table. Normally, the inserts happen straight away,
but when the reader is open each insert takes a very long time to
complete.

I realise that this is not an unreasonable thing to happen, given that I
am trying to write to the table whilst reading from it, but the rows
being written will never be included in the WHERE clause in my select
statement, and even if they were (which they won't), I wouldn't want them
included in the selected rows.

Is there a way to read rows so that inserts can still occur without
blocking?

I am using VB.NET in VS2005, and SQL Server 2005.

TIA

Charles


Jun 27 '08 #9
Charles Law wrote:
I have a sproc that returns data from a table using a simple SELECT.
There are quite a few rows returned, e.g. ~150,000.

In my first application, I use a reader on the sproc and iterate
through the rows, writing them out to a file. This takes about 5
minutes until I close the reader.
If you are doing

while moreRecords
begin
read record
write record to file
end

then maybe the writing to disk is the slow step, so how about

while moreRecords
begin
read record
append record to stringbuilder
end
write stringbuilder to file

?

I take it getting the sp to write to a file is not an option?

Andrew
Jun 27 '08 #10

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

Similar topics

6
2782
by: Chris Ochs | last post by:
I want to do a series of inserts within a single transaction block, but with postgresql if one insert fails, the whole block is aborted. Is there any way to get around this behavior so that postgresql won't abort the entire transaction if a single insert returns an error? Chris ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
18
1222
by: Charles Law | last post by:
I have a sproc that returns data from a table using a simple SELECT. There are quite a few rows returned, e.g. ~150,000. In my first application, I use a reader on the sproc and iterate through the rows, writing them out to a file. This takes about 5 minutes until I close the reader. Whilst this is going on, I have another application that is trying to insert rows into the table. Normally, the inserts happen straight away, but when...
0
9527
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
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
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
7546
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
6785
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();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
3730
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.