.NETGURU
Updating Access table through OleDb works but Odbc give Concurrency Violation error?!
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.odbcnet.

Post a new message to this list...

Kenneth Baltrinic
I developed a web site using the OleDb namespace, but I need to use an DSN
on the production web server and thus must convert the app to use Odbc
namespace. I have done this and all works find except for updating one
table. The following code example demonstrates the situation exactly. In
the code below example setting iTestCase to 0 results in "Success" being
outputted. Setting it to non-zero results in the following exception:

System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand
affected 0 records.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at TestConsole.Class1.Main(String[] args) in
f:\jobs\psc\testconsole\class1.cs:line 48

Not the ONLY difference between the two test cases in the code is the use of
the OleDb vs Odbc namespace for data access. Moreover I have simplified
this situation to the extreme. The test table tblTest has only two columns.
TestID is an autonumber and TestData is a DateTime. The record in question
of course already exists, and both columns are non-null. Any help would be
greatly appreciated. As a workaround, is there perchance a way to access a
DSN through OleDb?

using System;
using System.IO;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;

namespace TestConsole
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
int iTestCase = 1;

DataTable dt = new DataTable("Test");

if(iTestCase==0)
{
OleDbConnection conn = new
OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=F:\Server
Data\wwwroot\svsc\svsc.mdb");
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM tblTest WHERE
TestID=3", conn);
da.Fill(dt);

dt.Rows[0]["TestDate"] = DateTime.Now;

OleDbCommandBuilder cb = new OleDbCommandBuilder(da);

da.Update(dt);
}
else
{
OdbcConnection conn = new OdbcConnection(@"DSN=svsc");
OdbcDataAdapter da = new OdbcDataAdapter("SELECT * FROM tblTest WHERE
TestID=3", conn);
da.Fill(dt);

dt.Rows[0]["TestDate"] = DateTime.Now;

OdbcCommandBuilder cb = new OdbcCommandBuilder(da);

da.Update(dt);
}
Console.Write("Success");
}
catch(Exception ex)
{
Console.Write(ex.ToString());
}
Console.Read();
}
}
}

Reply to this message...
 
    
Kenneth Baltrinic
On the odd chance that my table was corrupt, I deleted it and recreated it.
Added a record by hand in access and reran the test. I discoved that Odbc
works just fine as long as you never used Oledb to update the table. Once
Oledb has done an update, Odbc cannot make updates. Moreover, this seems to
apply on a record by record basis. I can create a second new record and
again, its works find until OleDB is used to update it. Oledb reads appear
safe.

--Ken

Reply to this message...
 
 
System.Console
System.Data.Common.DataTableMapping
System.Data.Common.DbDataAdapter
System.Data.DataRow
System.Data.DataTable
System.Data.DBConcurrencyException
System.Data.Odbc.OdbcCommandBuilder
System.Data.Odbc.OdbcConnection
System.Data.Odbc.OdbcDataAdapter
System.Data.OleDb.OleDbCommandBuilder
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbDataAdapter
System.DateTime




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification