473,656 Members | 2,819 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_SysConcurre ncy
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
Nov 20 '05 #1
3 4328
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.goo gle.com...
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_SysConcurre ncy
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

Nov 20 '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
DBConcurrencyEx ception. 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******* *******@TK2MSFT NGP12.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

Nov 20 '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
DBConcurrencyEx ception. 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
Nov 20 '05 #4

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

Similar topics

1
1853
by: Bob T | last post by:
Hi, I have been using SQLDataAdapters and Datasets in my project. I have a goal to simplify the project. Each data adapter has a corresponding dataset it retrieves values into. Even though the data structure of 3 datasets is identical, the 3 data adapters use 3 different stored procedures depending on what I am trying to accomplish. It would seem that since the returned data fields are the same that I would
3
2437
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 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)
3
1232
by: Robin | last post by:
When adding a SQL Data Adapter to a page, is possible to configure it use a connection string in code? As I have found it regenerates the code each time and of the adapters are modified and does not allow the generate dataset option to be used.
5
1102
by: jonefer | last post by:
Just starting with ASP.NET and Pulling from data from an Access Database so I'm using the OleDbDataAdapter I'm trying to create two data adapters... daActorNames daActor I've successfully created daActor
2
931
by: Dave Cullen | last post by:
Can someone please explain the relationship between data adapters, connections, and datasets? Why would an application have one adapter and multiple data connection objects? Does each form that uses data need its own connection?
0
1178
by: dimpy | last post by:
Hi everyone, I am using some big size data adapters to fill datasets to be sent to a web service. Now every time i get an error in datatype or constraints violations while filling the dataset, I make changes to my data adapters on the form and run the application again. The problem I am facing is that the changes that I make to the adapter are reflected in the sql query builder straight away but somehow when I run the application, the...
2
1248
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 Adapters on many of the forms. These forms function fine in 2005 however I appear to be unable to configure the data adapters. In 2003 right clicking on the data adapter and selecting "Configure data adapter" allowed me to restructure the sql query...
1
1091
by: Justin | last post by:
We decided to upgrade to 2005 and upgrade our components. After fixing a few odds and end the upgrade was complete and our project was working fine. We didn't run into problems until we needed to ADD a table to our DB and update an existing Dataset. We have 9 data adapters in our project that pull different sets of data. I changed the Select statement on one of these adapters and noticed the datagrid didn't change. After messing with...
3
1231
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 adapter A into data adapter B via code?
1
1127
by: J | last post by:
I want to read a .csv file into a dataset using an OleDbDataAdapter, then update a SQL table from these rows. Is there any easier or more efficient way to do this instead of spinning through the dataset rows and firing off an INSERT for each of these rows? It seems to me that after I'd filled the dataset using the OleDbDataAdapter, I could create an SqlDataAdapter for use with this same dataset for updating. Seems as if I'd also need to...
0
8816
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
8717
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
8498
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
8600
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...
1
6162
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
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 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...

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.