K
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();
}
}
}
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();
}
}
}