Let's say that I am performing a bunch of insert/update queries within
a transaction that is created as follows:
Dim cnn As New
SqlClient.SqlCo nnection(My.Set tings.GRPConnec tionString)
cnn.Open()
Dim trx As SqlClient.SqlTr ansaction = cnn.BeginTransa ction()
Further suppose that, in the middle of all of the insert/update
queries, I want to execute a SELECT query against one of the tables
that is being affected by the aforementioned queries.
Will the SELECT query reflect changes made by them even if the
transaction has not yet been committed?
Do I have to use a separate connection to do the SELECT query? 6 5634
Bob,
You have normally only one connection, so everything is done one by one.
Cor
"BobRoyAce" <br**@omegasoft wareinc.comschr eef in bericht
news:70******** *************** ***********@79g 2000hsk.googleg roups.com...
Let's say that I am performing a bunch of insert/update queries within
a transaction that is created as follows:
Dim cnn As New
SqlClient.SqlCo nnection(My.Set tings.GRPConnec tionString)
cnn.Open()
Dim trx As SqlClient.SqlTr ansaction = cnn.BeginTransa ction()
Further suppose that, in the middle of all of the insert/update
queries, I want to execute a SELECT query against one of the tables
that is being affected by the aforementioned queries.
Will the SELECT query reflect changes made by them even if the
transaction has not yet been committed?
Do I have to use a separate connection to do the SELECT query?
BobRoyAce <br**@omegasoft wareinc.comwrot e:
Let's say that I am performing a bunch of insert/update queries within
a transaction that is created as follows:
-snip-
Will the SELECT query reflect changes made by them even if the
transaction has not yet been committed?
Yes. All commands within the transaction share the same scope. Think
about it, it has to be that way, otherwise a transaction would consist
of a single command.
Do I have to use a separate connection to do the SELECT query?
That depends upon what you want...
You should really play with Query Analyzer or SSMS, using transactions
and rollbacks and commits to see what does what you want to happen.
But let's briefly examine what *MIGHT* happen if you used two
connections
C1 -UPDATE Tbl Set Value = 1 Where Value = 2 -- ten rows effected
C2 -SELECT * FROM Tbl Where Value = 2 -- ten rows returned
But with two connections, that could happen because the command on C2
was executed before the command on C1 or while the command on C1 was
executing, or after and the transaction wasn't committed.
--
J.B. Moreno
"BobRoyAce" <br**@omegasoft wareinc.comwrot e in message
news:70******** *************** ***********@79g 2000hsk.googleg roups.com...
Let's say that I am performing a bunch of insert/update queries within
a transaction that is created as follows:
Dim cnn As New
SqlClient.SqlCo nnection(My.Set tings.GRPConnec tionString)
cnn.Open()
Dim trx As SqlClient.SqlTr ansaction = cnn.BeginTransa ction()
Further suppose that, in the middle of all of the insert/update
queries, I want to execute a SELECT query against one of the tables
that is being affected by the aforementioned queries.
The commit must be made, otherwise, the insert and updates have not been
applied to that database table.
>
Will the SELECT query reflect changes made by them even if the
transaction has not yet been committed?
Yes, you have to commit the changes.
>
Do I have to use a separate connection to do the SELECT query?
You do the Select after the transitions are committed, you don't need a
second connection, you use the same connection that's already being used
leave it open after the commit and you move the Select statement out from
the middle of the code that executing the transactions.
Let's say that I am performing a bunch of insert/update queries within
a transaction that is created as follows:
Dim cnn As New
SqlClient.SqlCo nnection(My.Set tings.GRPConnec tionString)
cnn.Open()
Dim trx As SqlClient.SqlTr ansaction = cnn.BeginTransa ction()
Further suppose that, in the middle of all of the insert/update
queries, I want to execute a SELECT query against one of the tables
that is being affected by the aforementioned queries.
Will the SELECT query reflect changes made by them even if the
transaction has not yet been committed?
Do I have to use a separate connection to do the SELECT query?
I've not used transactions with Sql Server and Visual Studio yet, but I have
used other DBMSs with other programming languages. How I would expect it to
work is that any query that you perform with a single connection, within the
scope of the same transaction, would see the changes that you have made,
even though the changes have not been committed to the database. Any other
connection, not within the scope of this transaction would not see the
changes until they have been committed. So whether you use a separate
connection or not depends on what you want to see.
Think of a transaction as working on a separate temporary copy of the
database.
For example
If I have a table with field 1 set to 1 in record 1, and I execute the
following SQL commands
--Begin Transaction --
UPDATE table1 SET field1=2 WHERE id=1
SELECT field1 FROM table1 WHERE id=1
I would expect this to return 2. However if the SELECT were performed using
a different connection I would expect it to return 1 (unless and until the
transaction is committed).
Things get a little more complicated if you have multiple transactions both
trying to update the same data.
I would conclude that I need to do the SELECT within the same
connection. However, the problem I was having, when trying to run with
a different connection, was that the query would just time out every
time. If I debugged through code, all the way up to, but not including
the SELECT query, then went to SQL Server Management Studio and tried
to run the SELECT query from there (while program execution is
suspended), I would get same result...timeou t. So, was just trying to
figure out why that would be happening...
"BobRoyAce" <br**@omegasoft wareinc.comwrot e in message
news:9a******** *************** ***********@m45 g2000hsb.google groups.com...
>I would conclude that I need to do the SELECT within the same
connection. However, the problem I was having, when trying to run with
a different connection, was that the query would just time out every
time. If I debugged through code, all the way up to, but not including
the SELECT query, then went to SQL Server Management Studio and tried
to run the SELECT query from there (while program execution is
suspended), I would get same result...timeou t. So, was just trying to
figure out why that would be happening...
MS.Public.SQLse rver.server This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jayson_13 |
last post by:
Hi,
I need to implement a counter and i face problem of locking so hope
that u guys can help me.
I try to do test like this :
1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
|
by: Nick Barr |
last post by:
Hi,
I am trying to gather stats about how many times a resource in our web
app is viewed, i.e. just a COUNT. There are potentially millions of
resources within the system.
I thought of two methods:
1. An extra column in the resource table which contains a count.
a. Each time a resource is viewed an UPDATE statement is run.
|
by: Ed L. |
last post by:
I think I'm seeing table-level lock contention in the following function
when I have many different concurrent callers, each with mutually distinct
values for $1. Is there a way to reimplement this function using
select-for-update (or equivalent) in order to get a row-level lock (and
thus less contention) while maintaining the function interface? The docs
seem to suggest so, but it's not clear how to return the SETOF queued_item
and also...
|
by: Grant McLean |
last post by:
Hi
First a simple question ...
I have a table "access_log" that has foreign keys "app_id" and
"app_user_id" that reference the "application_type" and "app_user"
tables. When I insert into "access_log", the referential integrity
triggers generate these queries:
SELECT 1 FROM ONLY "public"."application_type" x
|
by: Geoffrey KRETZ |
last post by:
Hello,
I'm wondering if the following behaviour is the correct one for
PostGreSQL (7.4 on UNIX).
I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :
INSERT INTO temp_tab VALUES (1,2,3)
| |
by: rAinDeEr |
last post by:
Hi,
I have a web application with a table to store terms and
conditions of a Company.
This may some times run into many pages and some times it may be just a
few sentences. It is a character text field. I want to know which Data
type I need to use so that it doesnt waste memory.
thanks in advance,
rAinDeEr
|
by: Steve |
last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement
I got ASP error number 13 when I use the SELECT...FOR UPDATE statement
as below.
However, if I use SELECT statement without FOR UPDATE, it is fine and
no error.
I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF
EMPNO"), but it still couldn't help.
any ideas? I tried to search in the web but couldn't find similar
|
by: lewindletter |
last post by:
Hi
If I do
Begin transaction
Stmt 1: select count(*) from tableA
If the count is zero, then proceed to the following
Stmt 2: insert "something" to tableA
Stmt 3: insert "something" to tableB
|
by: ThunderMusic |
last post by:
Hi,
We have a web application developped in asp.net (I think it's not relevant,
but well, it's so you know)... Yesterday, we received the following message
"Transaction (Process ID 69) was deadlocked on lock resources with another
process and has been chosen as the deadlock victim. Rerun the transaction. "
The thing is, the query was a simple select with inner joins between 3
tables (like select fields from table1 inner join table2......
|
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,...
|
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: 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,...
|
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: 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: 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
| |