PC Review


Reply
Thread Tools Rate Thread

Concurrency violation - concurrency_error_watch.xls (0/1)

 
 
nick
Guest
Posts: n/a
 
      10th Feb 2004
I'm having trouble updating from a datagrid. It's says "Concurrency
violation: the UpdateCommand affected 0 records", though I can't see
how it's related to "concurrency". I can insert and delete with no
problem. Here's the code that's causing the problem:

public void UpdateDataSource(Dancers.allbookings ChangedRows)
{
try
{
if ((ChangedRows != null))
{
this.oleDbConnection1.Open();
oleDbDataAdapter1.Update(ChangedRows);
}
}
catch (System.Exception updateException)
{
throw updateException;
}
finally
{
this.oleDbConnection1.Close();
}

}

An error occurs trying to execute the line:

oleDbDataAdapter1.Update(ChangedRows);

I found nothing wrong when trying to track from the watch list the
data from the row to be updated, as below (can be viewed a lot clearer
from the attached excel file):

- ChangedRows.tbprivate[0]
{Dancers.allbookings.tbprivateRow}
Dancers.allbookings.tbprivateRow
+ System.Data.DataRow {Dancers.allbookings.tbprivateRow}
System.Data.DataRow
cancelled FALSE bool
dancerid 6 int
finished TRUE bool
len 20 byte
pclub 30 short
pdancer 55 short
privateid 65 int
room A string
+ shift {8/2/2004} System.DateTime
start 20:20 string
+ tabletbprivate {Dancers.allbookings.tbprivateDataTable}
Dancers.allbookings.tbprivateDataTable
ChangedRows.Tables["tbprivate"].Rows[0].RowError
Concurrency violation: the UpdateCommand affected 0 records. string
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      10th Feb 2004
Hi Nick,

When you do it this way,
> oleDbDataAdapter1.Update(ChangedRows);


I asume that ChangedRows is the dataset.ChangedRows than the acceptchanges
is not done automaticly by the oleDbDataAdapter, the next time you do than
an update you get a concurrency errror.

Can it be that?

Cor


 
Reply With Quote
 
nick
Guest
Posts: n/a
 
      11th Feb 2004
On Tue, 10 Feb 2004 13:37:59 +0100, "Cor" <(E-Mail Removed)> wrote:

>Hi Nick,
>
>When you do it this way,
>> oleDbDataAdapter1.Update(ChangedRows);

>
>I asume that ChangedRows is the dataset.ChangedRows than the acceptchanges
>is not done automaticly by the oleDbDataAdapter, the next time you do than
>an update you get a concurrency errror.
>
>Can it be that?
>
>Cor
>


OK here's the code sequece: When the update button is pressed,
"UpdateDataSet" is called:

public void UpdateDataSet()
{
Dancers.allbookings objDataSetChanges = new
Dancers.allbookings();

this.BindingContext[objallbookings,"tbprivate"].EndCurrentEdit();
objDataSetChanges =
((Dancers.allbookings)(objallbookings.GetChanges()));

// Check to see if any changes have been made.
if ((objDataSetChanges != null))
{
try
{
this.UpdateDataSource(objDataSetChanges);
objallbookings.Merge(objDataSetChanges);
objallbookings.AcceptChanges();
}
catch (System.Exception eUpdate)
{
throw eUpdate;
}
}
}

which then calls "UpdateDataSource" from:

this.UpdateDataSource(objDataSetChanges);

"objDataSetChanges" is passed in as "ChangedRows" to
"UpdateDataSource". As mentioned before, it breaks down when executing
"oleDbDataAdapter1.Update(ChangedRows)" within "UpdateDataSource". I
suspect there's some data inconsistency but by looking at the
"ChangeRows" (which only have 1 row in this case) it all seems fine.
 
Reply With Quote
 
Tian Min Huang
Guest
Posts: n/a
 
      11th Feb 2004
Hello Nick,

Thanks for your post. As I understand, the problem you are facing is that
it throws DBConcurrencyException when calling DbDataAdapter.Update method.
By default, the Update method ends and raises a DBConcurrencyException
exception when the method encounters a row that fails to update. I think
more information is needed before moving forward:

1. What's the database, SQL Server, Microsoft Access, etc?

2. In the DataRow, does it contain the "System.Data.OleDb.OleDbType.DBDate"
type for mapping DateTime data? If so, based on my experience, there is a
known issue to cause such error and we need to use
System.DataOleDb.OleDbType.Date instead of
System.Data.OleDb.OleDbType.DBDate.

3. If the problem persists, is it possible for you to post a sample project
and database which is able to reproduce the problem? I will be glad to
check it on my side.

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
nick
Guest
Posts: n/a
 
      11th Feb 2004
On Wed, 11 Feb 2004 05:36:23 GMT, (E-Mail Removed) (Tian
Min Huang) wrote:

>Hello Nick,
>
>Thanks for your post. As I understand, the problem you are facing is that
>it throws DBConcurrencyException when calling DbDataAdapter.Update method.
>By default, the Update method ends and raises a DBConcurrencyException
>exception when the method encounters a row that fails to update. I think
>more information is needed before moving forward:
>
>1. What's the database, SQL Server, Microsoft Access, etc?


It's MSAccess.

>
>2. In the DataRow, does it contain the "System.Data.OleDb.OleDbType.DBDate"
>type for mapping DateTime data? If so, based on my experience, there is a
>known issue to cause such error and we need to use
>System.DataOleDb.OleDbType.Date instead of
>System.Data.OleDb.OleDbType.DBDate.


Here's the code to create the updatecommand for oleDbDataAdapter1:

updatesql = "UPDATE tbprivate SET dancerid = @dancerid, len = @len,
start = @start, pdancer = @pdancer, pclub = @pclub, room = @room,
finished = @finished, cancelled = @cancelled, shift = #" + GetShift()
+ "# WHERE privateid = @privateid";

where GetShift() will return a date like "2/8/2004".

oleDbDataAdapter1.UpdateCommand = new
OleDbCommand(updatesql,oleDbConnection1);
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@privateid",
OleDbType.BigInt,4, "privateid");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@dancerid",
OleDbType.BigInt,4, "dancerid");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@len",
OleDbType.TinyInt,1, "len");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@room",
OleDbType.VarChar,1, "room");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@start",
OleDbType.VarChar,5, "start");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@pclub",
OleDbType.TinyInt,4, "pclub");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@pdancer",
OleDbType.TinyInt,4, "pdancer");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@finished",
OleDbType.Boolean,1, "finished");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@cancelled",
OleDbType.Boolean,1, "cancelled");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@shift",
OleDbType.Date,0, "shift");
 
Reply With Quote
 
nick
Guest
Posts: n/a
 
      11th Feb 2004
Also have you looked at the xls file? Is it useful?

On Wed, 11 Feb 2004 05:36:23 GMT, (E-Mail Removed) (Tian
Min Huang) wrote:

>Hello Nick,
>
>Thanks for your post. As I understand, the problem you are facing is that
>it throws DBConcurrencyException when calling DbDataAdapter.Update method.
>By default, the Update method ends and raises a DBConcurrencyException
>exception when the method encounters a row that fails to update. I think
>more information is needed before moving forward:
>
>1. What's the database, SQL Server, Microsoft Access, etc?
>
>2. In the DataRow, does it contain the "System.Data.OleDb.OleDbType.DBDate"
>type for mapping DateTime data? If so, based on my experience, there is a
>known issue to cause such error and we need to use
>System.DataOleDb.OleDbType.Date instead of
>System.Data.OleDb.OleDbType.DBDate.
>
>3. If the problem persists, is it possible for you to post a sample project
>and database which is able to reproduce the problem? I will be glad to
>check it on my side.
>
>I look forward to hearing from you.
>
>Regards,
>
>HuangTM
>Microsoft Online Partner Support
>MCSE/MCSD
>
>Get Secure! -- www.microsoft.com/security
>This posting is provided "as is" with no warranties and confers no rights.


 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      11th Feb 2004
Hi Nick,

What is the reason you do this,
> this.UpdateDataSource(objDataSetChanges);
> objallbookings.Merge(objDataSetChanges);
> objallbookings.AcceptChanges();


If I see it good you try to merge to the dataset a set of rows which are
already completly in this dataset if the program works correct than that
should give an concurrency error..

I think it is better to do an update of the whole dataset. (I have done it a
while a little bit the same as you although without the merge, I am not
secure if all checkings are done correct with this method).

You do than also not need that acceptchanges, because the dataadapter does
it for you if everything went correct.

Cor


 
Reply With Quote
 
nick
Guest
Posts: n/a
 
      11th Feb 2004
On Wed, 11 Feb 2004 13:02:24 +0100, "Cor" <(E-Mail Removed)> wrote:

>Hi Nick,
>
>What is the reason you do this,
>> this.UpdateDataSource(objDataSetChanges);
>> objallbookings.Merge(objDataSetChanges);
>> objallbookings.AcceptChanges();


objallbookings is the existing dataset. UpdateDataSource updates the
underlying datasource (actually updating the database). The last 2
lines commits changes to the dataset. How else would you do it??

>
>If I see it good you try to merge to the dataset a set of rows which are
>already completly in this dataset if the program works correct than that
>should give an concurrency error..


See above.

>
>I think it is better to do an update of the whole dataset. (I have done it a
>while a little bit the same as you although without the merge, I am not
>secure if all checkings are done correct with this method).


I have been doing it this way ALL the time, only this particular grid
fails me. I am suspecting it's the data in the row(s) that's giving
the underlying database inconsistent update, but I can't figure out
which column, cause as you can see from the watch (excel file) all
data seems pretty normal.

Anyone?
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      11th Feb 2004
Hi Nick,

I would first try what I did advice when than the concurrency error is not
gonne than it is something else.

:-)

Cor

> I have been doing it this way ALL the time, only this particular grid
> fails me. I am suspecting it's the data in the row(s) that's giving
> the underlying database inconsistent update, but I can't figure out
> which column, cause as you can see from the watch (excel file) all
> data seems pretty normal.
>



 
Reply With Quote
 
nick
Guest
Posts: n/a
 
      11th Feb 2004
On Wed, 11 Feb 2004 14:34:17 +0100, "Cor" <(E-Mail Removed)> wrote:

>Hi Nick,
>
>I would first try what I did advice when than the concurrency error is not
>gonne than it is something else.
>
>:-)
>
>Cor


Umm.. I don't quite understand what you're suggesting. Perhaps some
code might help?

>
>> I have been doing it this way ALL the time, only this particular grid
>> fails me. I am suspecting it's the data in the row(s) that's giving
>> the underlying database inconsistent update, but I can't figure out
>> which column, cause as you can see from the watch (excel file) all
>> data seems pretty normal.
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concurrency violation Dave Microsoft ADO .NET 5 21st Nov 2006 11:33 AM
Concurrency Violation elziko Microsoft VB .NET 4 18th Feb 2005 12:47 PM
Concurrency violation - concurrency_error_watch.xls (0/1) nick Microsoft C# .NET 1 11th Feb 2004 09:09 AM
Concurrency Violation Nathan Microsoft ADO .NET 2 25th Jan 2004 11:20 PM
Concurrency Violation Hill Cheung Microsoft ADO .NET 1 4th Jul 2003 09:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:26 AM.