Hello Newsgroup,
I have written a very short program to get information from a whole
table out of a database. the problem is that other people couldn't
work on this table during the process. It seems that my program locks
the whole table.
I used the DataReader from the .NET Framework. Can you please take a
look at the code and give me any solution??? Thank very much, Nils
Dim strSQL As String = "SELECT * FROM TESTTABLE"
Dim Conn As System.Data.Sql Client.SqlConne ction = New
System.Data.Sql Client.SqlConne ction("Data Source=1.1.1.1;
User ID=sa;Password= secret;Persist Security Info=True;
Initial Catalog=TestDB" )
Conn.Open()
Dim SqlCmd As SqlCommand = New SqlCommand(strS QL,Conn)
Dim DR As System.Data.Sql Client.SqlDataR eader
Try
DR = SqlCmd.ExecuteR eader
Do While DR.Read()
<only reading with DR.item("column name")>
Loop
Catch ex As Exception
errorhandler(ex .ToString)
Finally
If DR.IsClosed = False Then DR.Close()
SqlCmd.Dispose( )
End Try 5 8575
Nils Pommerien (fi******@gmx.d e) writes: I have written a very short program to get information from a whole table out of a database. the problem is that other people couldn't work on this table during the process. It seems that my program locks the whole table. I used the DataReader from the .NET Framework. Can you please take a look at the code and give me any solution??? Thank very much, Nils
Dim strSQL As String = "SELECT * FROM TESTTABLE"
Well, a SELECT * from a table without any WHERE condition will require
the entire table to be locked while you get the data. Other people
should still be able to read from the table, but updates will not
be possible.
If the table is small, this is not much of an issue, because unless
you go do some huge processing for each row. But if the table is big,
you will held the locks for quite some time. In such case I would
question the wise in getting so much data to the client.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Erland,
Would a "SELECT * FROM TABLE WITH NOLOCK" work in his case? Assuming he
does not care if the data changes.
Oscar...
"Erland Sommarskog" <so****@algonet .se> wrote in message
news:Xn******** *************@1 27.0.0.1... Nils Pommerien (fi******@gmx.d e) writes: I have written a very short program to get information from a whole table out of a database. the problem is that other people couldn't work on this table during the process. It seems that my program locks the whole table. I used the DataReader from the .NET Framework. Can you please take a look at the code and give me any solution??? Thank very much, Nils
Dim strSQL As String = "SELECT * FROM TESTTABLE"
Well, a SELECT * from a table without any WHERE condition will require the entire table to be locked while you get the data. Other people should still be able to read from the table, but updates will not be possible.
If the table is small, this is not much of an issue, because unless you go do some huge processing for each row. But if the table is big, you will held the locks for quite some time. In such case I would question the wise in getting so much data to the client.
Oscar Santiesteban Jr. (os************ ***@worldnet.at t.net) writes: Erland,
Would a "SELECT * FROM TABLE WITH NOLOCK" work in his case? Assuming he does not care if the data changes.
No that would not work:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'nolock'.
But:
SELECT * FROM tbl WITH (NOLOCK)
would of course the remove the locking problems. I didn't mention this
possibility, because I had a feeling that he his real problem one of:
1) He's getting far more rows than he has use for.
2) He's doing something long-winding between the retrieval of each row.
So the NOLOCK would only be a band-aid on a poor design.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Erland, a question for you, I've noticed that the NOLOCK statement
generates more logical IO than selecting from the entire table, do you
know the cause?
Ray Higdon MCSE, MCDBA, CCNA
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ray Higdon (ra*******@higd onconsulting.co m) writes: Erland, a question for you, I've noticed that the NOLOCK statement generates more logical IO than selecting from the entire table, do you know the cause?
Eh, could you provide a repro?
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hal |
last post by:
I am experiencing blocking problems on SQL Server 2000, SP3a. I have
read the posts and set up a job SQL agent to report on these
occurences I save the results to a table before executing an sp to
kill the offending process id. I am puzzled as to how a process that
does no updating can be guilty of blocking. Typically, I think what
is happening is a process that does no updates is blocking processes
that are trying to do updates. Can...
|
by: Grant |
last post by:
I am connecting to an access database using a datareader in C#. I get
results when I run a certain query from Access but when I run it from Code
it does not retrieve any results. I have put a stop point after the string
is created and it is correct. Its an inner join query so I was wandering
whether that is too complicated for a datareader to execute, or if Im
missing something else here?
Heres what Im doing in code:
...
|
by: Ivan Weiss |
last post by:
Hey all, I have the following code to populate a ListView control from
my Access database. The listview is displaying a list of saved projects
that the user will be able to open, edit, or delete to work on. I know
that the DataReader is more efficient and faster than a dataset, but I
was not able to figure out how to implement it. Here is the code I have
now which works:
Private Sub frmProjects_Load(ByVal sender As System.Object,...
|
by: loosecannon_1 |
last post by:
I get a 90-120 second blocking when send 15 or so simultaneous queries
to SQL Server 2000 that query a view made up of two joined tables.
After each query is blocking for the same amount of time they all
return. Further identical queries of this type work in 3-4 seconds
(caching?) until hours later where it happens again. If I query the
tables directly (without the view) I still get the same blocking. If I
remove the join (it is a simple...
|
by: ^MisterJingo^ |
last post by:
Hi all,
I have a form with 4 dropdownlist controls which I populate with data
from DB tables. I have a class with a method which constructs a
dataset, putting each DB table into a dataset table. I then return the
DS and bind the tables to the relevant controls.
I've been reading that DataReaders are much more efficient than
DS's for getting data from the database.
So would it better to have 4 methods, each returning a dataReader, or...
| |
by: neilr |
last post by:
Can anyone help with some problkems that have wasted 2 days of my
(inexperienced) time already?
We have a website which allows people to register for events like
conferences
We are importing a table of fees for the apporpriate event using an Sp:
FeesDataSet = New System.Data.DataSet
Dim MySPcommand As New System.Data.SqlClient.SqlCommand
MySPcommand.CommandText = "SP4105201getWebFeeTable"
|
by: Steve |
last post by:
Hi, I currently display all the data on a website using tableadaptors
and objectdatasources.
Would it be significantly faster if I was to display the data by
writing the code for a datareader and connecting to the database
directly and populating my tables that way?
Or is the tableadaptor using a datareader anyway for simple select
statements?
|
by: =?Utf-8?B?R3JlZyBTdGV2ZW5z?= |
last post by:
I am connecting to an Oracle database using an OleDbConnection. I am using
DataReader objects to get query results. However, this limits me to only
having one reader open at a time, which is a problem for one of the
operations I am doing.
I have a table with hierarhical data (only 3 levels deep) that I would like
to parse through in a depth-first search. Each row in the table in the
database has a Name and a ParentName, and I'm doing...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
I'm trying to add a datagridview control to a Windows Form to display
read-only information in visual basic 2005. My understanding is that
datareader will be faster for this purpose. I have the following questions:
1. Can DataReader be bound DIRECTLY to DataGridView?
2. If DataReader cannot be bound directly to DataGridView, how can I load a
DataReader into a DataTable and bind the DataTable to DataGridView? Can the
DataTable be a...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |