Concurrency Violation Exception

T

Tom Jorgenson

I'm using disconnected datasets in an ASP.NET web application. I'm using the
automatic locking (that is, I'm not doing anything myself to cause a lock
other than calling an update).

When I go to persist a change in a dataset, it generates a concurrency
violation exception.

The only problem is that I'm the only user of the SQL Server (as well as the
database and table) and this is the FIRST update that's been applied to the
table during this session. This isn't even a new record in the table (or I
might suspect getting caught somehow by a default entry).

So, how can I get a concurrency violation on a table record that couldn't
have been modified after the dataset was originally loaded?

Another question, is it true that the lock (in automatic locking) is applied
only during the update? Could the record somehow have remained locked in the
table even after the session has died? If so, how can it be released
manually?

I'm stumped.
 
W

William \(Bill\) Vaughn

I suspect that the exception being raised is telling you that ADO.NET
"thinks" there is a concurrency violation. When an Update method is
executed, ADO.NET expects to hear back from the server that 1 row (and only
1 row) was affected. If something went wrong during the Update (someone
changed the row after you read it, the row was deleted, or anything that
would change the RowsAffected value) ADO.NET will throw a "concurrency"
exception.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
M

Miha Markic

In addition to Bill, can you show us your adapter (including commands) code?
 
T

Tom Jorgenson

this.sqlDataAdapterYouth = new System.Data.SqlClient.SqlDataAdapter();

//
// sqlDataAdapterYouth
//
this.sqlDataAdapterYouth.DeleteCommand = this.sqlDeleteCommandYouth;
this.sqlDataAdapterYouth.InsertCommand = this.sqlInsertCommandYouth;
this.sqlDataAdapterYouth.SelectCommand = this.sqlSelectCommandYouth;
this.sqlDataAdapterYouth.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "YOUTH", new
System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("youthID", "youthID"),
new System.Data.Common.DataColumnMapping("firstName", "firstName"),
new System.Data.Common.DataColumnMapping("initial", "initial"),
new System.Data.Common.DataColumnMapping("lastName", "lastName"),
new System.Data.Common.DataColumnMapping("dateOfBirth",
"dateOfBirth"),
new System.Data.Common.DataColumnMapping("socialSecurity",
"socialSecurity"),
new System.Data.Common.DataColumnMapping("streetAddress1",
"streetAddress1"),
new System.Data.Common.DataColumnMapping("streetAddress2",
"streetAddress2"),
new System.Data.Common.DataColumnMapping("city", "city"),
new System.Data.Common.DataColumnMapping("state", "state"),
new System.Data.Common.DataColumnMapping("zip", "zip"),
new System.Data.Common.DataColumnMapping("gender", "gender"),
new System.Data.Common.DataColumnMapping("emailAddress",
"emailAddress"),
new System.Data.Common.DataColumnMapping("ethnicity", "ethnicity"),
new System.Data.Common.DataColumnMapping("religion", "religion"),
new System.Data.Common.DataColumnMapping("familyEconomicStatus",
"familyEconomicStatus"),
new System.Data.Common.DataColumnMapping("homeAtAdmission",
"homeAtAdmission"),
new System.Data.Common.DataColumnMapping("problemSchoolBehavior",
"problemSchoolBehavior"),
new System.Data.Common.DataColumnMapping("poorAcademics",
"poorAcademics"),
new System.Data.Common.DataColumnMapping("runAlways", "runAlways"),
new System.Data.Common.DataColumnMapping("poorRelationships",
"poorRelationships"),
new System.Data.Common.DataColumnMapping("lyingOrCheating",
"lyingOrCheating"),
new System.Data.Common.DataColumnMapping("defianceOrAggression",
"defianceOrAggression"),
new System.Data.Common.DataColumnMapping("lackOfImpulseControl",
"lackOfImpulseControl"),
new System.Data.Common.DataColumnMapping("hyperactivity",
"hyperactivity"),
new System.Data.Common.DataColumnMapping("drugEnvironment",
"drugEnvironment"),
new System.Data.Common.DataColumnMapping("alcoholEnvironment",
"alcoholEnvironment"),
new System.Data.Common.DataColumnMapping("criminalInvolvement",
"criminalInvolvement"),
new System.Data.Common.DataColumnMapping("notApplicable",
"notApplicable"),
new System.Data.Common.DataColumnMapping("singleParent",
"singleParent"),
new System.Data.Common.DataColumnMapping("neglected", "neglected"),
new System.Data.Common.DataColumnMapping("abused", "abused"),
new System.Data.Common.DataColumnMapping("abandoned", "abandoned"),
new System.Data.Common.DataColumnMapping("noSupervisionOrControl",
"noSupervisionOrControl"),
new System.Data.Common.DataColumnMapping("alcoholicAddictedParent",
"alcoholicAddictedParent"),
new System.Data.Common.DataColumnMapping("disabledParent",
"disabledParent"),
new System.Data.Common.DataColumnMapping("incomeBelowPoverty",
"incomeBelowPoverty"),
new System.Data.Common.DataColumnMapping("unsafeNeighborhood",
"unsafeNeighborhood"),
new System.Data.Common.DataColumnMapping("educationOpportunities",
"educationOpportunities"),
new System.Data.Common.DataColumnMapping("other", "other"),
new System.Data.Common.DataColumnMapping("socialNotApplicable",
"socialNotApplicable")})});
this.sqlDataAdapterYouth.UpdateCommand = this.sqlUpdateCommandYouth;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top