473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net data adapters - concurrency and insert comands

Hi All

I'm having problems getting my data adapter to throw a concurrency
exception with an INSERT command. I want to throw a concurrency
exception if an attempt is made to enter a row into tb_table when a
row with the same int_UID already exists in there.

Here is my stored procedure:

if not exists (select int_UID from tb_table where int_UID = @aint_UID)
begin
insert into tb_tables (int_UID, str_val1, str_val2)
values (@aint_UID, one, two)
end
else
begin
update xtb_SysConcurrency
set str_Update = 'No'
where int_Counter = -1
end

As you can see I'm trying to "force" 0 rows affected back to the data
adapter if the insert fails so that a concurrency exception is raised.
I thought that this was how it works .. 0 rows affected is interpreted
as a concurrency violation?

The problem is that although the second time the stored procedure is
run for the same UID, it (correctly) never does insert a row into the
table, however neither does it raise a concurrency violation.

I have tested my stored procedure in query analyser and can confirm
the second time it runs for the same UID it does come back with the
message 0 rows affected. Also I'm sure I have configured my data
adapter correctly as everything works just fine with update commands.
So what's going on? Does the INSERT command of the data Adapter not
respond to 0 rows affected?

Any help would be gratefully appreciated.

Thank you
Suzanne
Jul 21 '05 #1
3 2413
Hi Suzanne,

This is not a cuncurrency issue at all. Concurrency means that a user has
edited a record and saved it (or deleted) while you were editing the same
record.
Insert command can never produce a concurrency violation - that's why it is
never checked.
You shuld rather put a unique constraint on the column(s) and let database
throw you an unique constraint violation without any special code.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Suzanne" <sj***********@mhapensions.com> wrote in message
news:3c**************************@posting.google.c om...
Hi All

I'm having problems getting my data adapter to throw a concurrency
exception with an INSERT command. I want to throw a concurrency
exception if an attempt is made to enter a row into tb_table when a
row with the same int_UID already exists in there.

Here is my stored procedure:

if not exists (select int_UID from tb_table where int_UID = @aint_UID)
begin
insert into tb_tables (int_UID, str_val1, str_val2)
values (@aint_UID, one, two)
end
else
begin
update xtb_SysConcurrency
set str_Update = 'No'
where int_Counter = -1
end

As you can see I'm trying to "force" 0 rows affected back to the data
adapter if the insert fails so that a concurrency exception is raised.
I thought that this was how it works .. 0 rows affected is interpreted
as a concurrency violation?

The problem is that although the second time the stored procedure is
run for the same UID, it (correctly) never does insert a row into the
table, however neither does it raise a concurrency violation.

I have tested my stored procedure in query analyser and can confirm
the second time it runs for the same UID it does come back with the
message 0 rows affected. Also I'm sure I have configured my data
adapter correctly as everything works just fine with update commands.
So what's going on? Does the INSERT command of the data Adapter not
respond to 0 rows affected?

Any help would be gratefully appreciated.

Thank you
Suzanne

Jul 21 '05 #2
Hi Miha,
thanks for responding... I see your point and I do understand the
reasons.
The thing was - in the table I was trying to update - the column of my
int_UID is not /can not be unique (i.e. it is not the ID column for
this table).

However in the situation when 2 users download the same info at the
same time from the db then attempt to insert at the same time, I
wanted the second user to update the table to know that a row had been
inserted since they downloaded the data... thus I was trying to force
0 rows affected back to try and fabricate a concurrency violation.

Thanks for confirming the behaviour that on a insert command the data
adapter will not respond to 0 rows affected by generating a
DBConcurrencyException. I can now tackle things in a different way.. I
think what I must do instead is to raise an error in sql then catch it
in .net

Again thanks for the help

Suzanne

"Miha Markic" <miha at rthand com> wrote in message news:<#f**************@TK2MSFTNGP12.phx.gbl>...
Hi Suzanne,

This is not a cuncurrency issue at all. Concurrency means that a user has
edited a record and saved it (or deleted) while you were editing the same
record.
Insert command can never produce a concurrency violation - that's why it is
never checked.
You shuld rather put a unique constraint on the column(s) and let database
throw you an unique constraint violation without any special code.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Jul 21 '05 #3
Hi Suzanne,

....
Thanks for confirming the behaviour that on a insert command the data
adapter will not respond to 0 rows affected by generating a
DBConcurrencyException. I can now tackle things in a different way.. I
think what I must do instead is to raise an error in sql then catch it
in .net
That is certainly one way.
Again thanks for the help


You're welcome :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
Jul 21 '05 #4

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

Similar topics

5
2116
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
3
4324
by: Suzanne | last post by:
Hi All I'm having problems getting my data adapter to throw a concurrency exception with an INSERT command. I want to throw a concurrency exception if an attempt is made to enter a row into...
2
3472
by: BobAchgill | last post by:
Do you know why this error might be happening? Maybe it is because I have two data adapters open on the same MDB file?? If this is the problem... how can I keep them from disturbing each other?...
4
2299
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1,...
2
1243
by: Paul Craig | last post by:
Hi everyone, I have recently upgraded several of my projects from Visual Studio 2003 to 2005 and everything went across quite smoothly. The main problem that I am having is I have used SQL Data...
17
3500
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
3
1223
by: John | last post by:
Hi I have two data adapters bound to two separate tables. How can I; 1. Loop through all records one by one in one of them while reading column values, and 2. Insert a record from data...
3
1407
by: John | last post by:
Hi I have a vs 2003 winform data app. All the data access code has been generated using the data adapter wizard and then pasted into the app. The problem I have is that I am getting a data...
12
19932
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
0
7070
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...
0
7316
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...
1
6976
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...
0
4666
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...
0
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
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...

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.