HighTechTalks DotNet Forums  

tableadapters, where is my concurrency exception?

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss tableadapters, where is my concurrency exception? in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old   
troy@makaro.com
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-29-2006 , 12:36 PM






oops. I accidentally posted that without the testdataset.designer.cs
snippet. Here it is:

FYI: a snippet of the testdataset.designer.cs:

this._adapter.UpdateCommand.CommandText = "UPDATE [dbo].[Test] SET
[count] = @count WHERE (([TestId] = @Original_TestId) AND" +
" ([count] = @Original_count));\r\nSELECT TestId, count FROM Test
WHERE (TestId = @" +
"TestId)";


Reply With Quote
  #12  
Old   
Theo Verweij
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-29-2006 , 03:50 PM






With your update statement you won't get an exception;
Your where:
WHERE (TestId = @Original_TestId) AND (count = @Original_count)

So, the update only takes place on the row when testid didn't change and
count didn't change.

So, when you encounter a concurrency problem (when one or both have
changed) the count of rows that are updated will be 0 -> no row has been
updated.

When another value in the row has changed (assumed that the table
contains more than 2 cols), your update will succeed, again without a
concurrency exception.

This is because sqlclient works with disconnected recordsets (the reason
you need an update statement); to work with optimistic concurrency with
real concurrency checks, you need a connected recordset, so your updates
can use the rowversion.

An article explaning this:
http://www.ftponline.com/vsm/2003_10...databasedesign

But, you can check your concurrency based on the columnvalues; if there
is no row containing those values, a concurrency error is raised (I did
not test this):

IF NOT EXISTS(SELECT * FROM TEST WHERE (TestId = @Original_TestId) AND
(count = @Original_count))
BEGIN
RAISERROR(16934,10,16)
--Optimistic concurrency check failed.
--The row was modified outside of this cursor.
END
ELSE
BEGIN
UPDATE Test
SET count = @count
WHERE (TestId = @Original_TestId) AND (count = @Original_count)
END



troy (AT) makaro (DOT) com wrote:
Quote:
Hi, I wrote a very simple program to test concurrency with sql server
2005. I used the VS 2005 dataset designer wizard to create my dataset
and and tableadapter.

When I ran the program, I used the debugger to stop the code before the
tableadapter.update(row) method was called. I then ran the server
explorer and modified the data row and then continued with the program.
To my surprise, no error was thrown! The row was not updated(as
expected) because the where clause did not match.

How do I check for concurrency?

My test data table has two columns. the first column is an auto
incremented integer primary key. The second column is just and integer
field.

Here is my program:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConcurrencyTest {
class Program {
static void Main(string[] args)
{
TestDataSet testDS = new TestDataSet();

TestDataSetTableAdapters.TestTableAdapter testTA = new
TestDataSetTableAdapters.TestTableAdapter();

TestDataSet.TestDataTable testDT = testTA.GetDataBy(1000);
TestDataSet.TestRow testRow = testDT[0];
testRow.count++;
try {
testTA.Update(testRow);
} catch (DBConcurrencyException e) {
String data = e.Message;
} catch (Exception e) {
String data = e.Message;
}
}
}
}

here is what the update looks like:

UPDATE Test
SET count = @count
WHERE (TestId = @Original_TestId) AND (count = @Original_count)

Troy


Reply With Quote
  #13  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-29-2006 , 05:01 PM



Troy,

Something crazy is happening, I will probably search for this tomorrow.

There are no update commands anymore generated on my computer.

(Maybe am I blind now, so maybe it goes tomorrow better)

I did it with other databases, with VB and with C#, every time the same.

Cor

<troy (AT) makaro (DOT) com> schreef in bericht
news:1156869394.881295.38780 (AT) h48g2000cwc (DOT) googlegroups.com...
Quote:
oops. I accidentally posted that without the testdataset.designer.cs
snippet. Here it is:

FYI: a snippet of the testdataset.designer.cs:

this._adapter.UpdateCommand.CommandText = "UPDATE [dbo].[Test] SET
[count] = @count WHERE (([TestId] = @Original_TestId) AND" +
" ([count] = @Original_count));\r\nSELECT TestId, count FROM Test
WHERE (TestId = @" +
"TestId)";




Reply With Quote
  #14  
Old   
troy@makaro.com
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 01:11 AM



Did you remember to set your primary key? I heard that without it the
update does not get generated.

Troy

Cor Ligthert [MVP] wrote:
Quote:
Troy,

Something crazy is happening, I will probably search for this tomorrow.

There are no update commands anymore generated on my computer.
[snip]



Reply With Quote
  #15  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 01:42 AM



Troy,

That I tried this morning, I had forget it, but I added it and in the table
and in the dataset but had the same result, I will go on. But probably it
takes more time, I am almost sure that it almost was going before.

Cor

<troy (AT) makaro (DOT) com> schreef in bericht
news:1156914679.191926.75230 (AT) m73g2000cwd (DOT) googlegroups.com...
Quote:
Did you remember to set your primary key? I heard that without it the
update does not get generated.

Troy

Cor Ligthert [MVP] wrote:
Troy,

Something crazy is happening, I will probably search for this tomorrow.

There are no update commands anymore generated on my computer.
[snip]




Reply With Quote
  #16  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 02:13 AM



Troy,

I see the update command again, but I have to go soon, so probably you would
have to wait a while.

The strange thing is that I had installed yesterday temporally VB6, I have
deinstalled and as far as I can see now everythings goes fine. There should
not be a connection however maybe to watch for in this newsgroup. I have
more seen messages "there is no correct update command" from which I thought
it was impossible.

Cor

<troy (AT) makaro (DOT) com> schreef in bericht
news:1156914679.191926.75230 (AT) m73g2000cwd (DOT) googlegroups.com...
Quote:
Did you remember to set your primary key? I heard that without it the
update does not get generated.

Troy

Cor Ligthert [MVP] wrote:
Troy,

Something crazy is happening, I will probably search for this tomorrow.

There are no update commands anymore generated on my computer.
[snip]




Reply With Quote
  #17  
Old   
troy@makaro.com
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 02:22 AM



I think I found the problem. See:
http://search.support.microsoft.com/...d=8291&sid=200
I haven't been able to get the hotfix yet to try it though.

[snip]


Reply With Quote
  #18  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 06:26 AM



Troy ,

I don't think so,

If I was using as you had showed, (what was fine for me, I never did it that
way), than the update was *not* processed. Because I always use a datatable
attached to the Server I have attached that created one.

In that case when I set a breakpoint before the update, changed it as you
wrote and went on, I got a concurrency error (nd when I did not change it
not)

"Inbreuk op gelijktijdige uitvoering: 0 van de verwachte 1 records zijn
beïnvloed door de UpdateCommand."

If you don't believe me, ask somebody who speaks Dutch

To summarize with the not connected mdf file the update was completely not
processed.

I did it now in a windowform, but that did it either with a standalone mdf
as I have tested this.
I have not tested it with a consoleapplication but I expect the same
results.

I hope you get the same result.

Cor

<troy (AT) makaro (DOT) com> schreef in bericht
news:1156918959.393633.39410 (AT) p79g2000cwp (DOT) googlegroups.com...
Quote:
I think I found the problem. See:
http://search.support.microsoft.com/...d=8291&sid=200
I haven't been able to get the hotfix yet to try it though.

[snip]




Reply With Quote
  #19  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-30-2006 , 07:08 AM



Hi,

I have the sent the bug to the feedback center.

Cor

"Cor Ligthert [MVP]" <notmyfirstname (AT) planet (DOT) nl> schreef in bericht
news:uTMgV6BzGHA.3464 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Quote:
Troy ,

I don't think so,

If I was using as you had showed, (what was fine for me, I never did it
that way), than the update was *not* processed. Because I always use a
datatable attached to the Server I have attached that created one.

In that case when I set a breakpoint before the update, changed it as you
wrote and went on, I got a concurrency error (nd when I did not change it
not)

"Inbreuk op gelijktijdige uitvoering: 0 van de verwachte 1 records zijn
beïnvloed door de UpdateCommand."

If you don't believe me, ask somebody who speaks Dutch

To summarize with the not connected mdf file the update was completely not
processed.

I did it now in a windowform, but that did it either with a standalone mdf
as I have tested this.
I have not tested it with a consoleapplication but I expect the same
results.

I hope you get the same result.

Cor

troy (AT) makaro (DOT) com> schreef in bericht
news:1156918959.393633.39410 (AT) p79g2000cwp (DOT) googlegroups.com...
I think I found the problem. See:
http://search.support.microsoft.com/...d=8291&sid=200
I haven't been able to get the hotfix yet to try it though.

[snip]






Reply With Quote
  #20  
Old   
troy@makaro.com
 
Posts: n/a

Default Re: tableadapters, where is my concurrency exception? - 08-31-2006 , 06:06 PM



Hi Cor, I just updated my computer with the hotfix 915880 from
Microsoft and you are correct, It doesn't work. FYI, I am Dutch!
Although I was born in Canada and only speak english

Troy

Cor Ligthert [MVP] wrote:
Quote:
Troy ,

I don't think so,

If I was using as you had showed, (what was fine for me, I never did it that
way), than the update was *not* processed. Because I always use a datatable
attached to the Server I have attached that created one.

In that case when I set a breakpoint before the update, changed it as you
wrote and went on, I got a concurrency error (nd when I did not change it
not)

"Inbreuk op gelijktijdige uitvoering: 0 van de verwachte 1 records zijn
beïnvloed door de UpdateCommand."

If you don't believe me, ask somebody who speaks Dutch

To summarize with the not connected mdf file the update was completely not
processed.

I did it now in a windowform, but that did it either with a standalone mdf
as I have tested this.
I have not tested it with a consoleapplication but I expect the same
results.

I hope you get the same result.

Cor

troy (AT) makaro (DOT) com> schreef in bericht
news:1156918959.393633.39410 (AT) p79g2000cwp (DOT) googlegroups.com...
I think I found the problem. See:
http://search.support.microsoft.com/...d=8291&sid=200
I haven't been able to get the hotfix yet to try it though.

[snip]



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.