Problem with ADO
From: Bill Thompson (billt61_at_rgv.rr.com)
Date: 09/30/04
- Next message: Bill Thompson: "Re: Problem with ADO"
- Previous message: Joshua Weir: "Re: Change the name of my application"
- Next in thread: Bill Thompson: "Re: Problem with ADO"
- Reply: Bill Thompson: "Re: Problem with ADO"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Sep 2004 02:09:13 -0500
I am using a Microsoft Jet Engine database.
While testing an ADO implementation, I found that I ran into trouble if I
repeatedly tried to update the field with the 'too large' data; eventually
ADO became convinced that I had never issued an Edit or AddNew. Of course,
Edit does not exist in ADO; the edit is implied when you try to set a field.
To make sure the error wasn't elsewhere, I have removed all wrapper
functions and created this test case that reproduces the error using
primitives.
I have discovered that issuing a CancelUpdate() clears the error, but then
any other edits the user has made are discarded. Of course I can work
around by saving all user changes and posting them again, but it would be
nice if there is a better way to deal with this situation.
Thanks.
Source Code:
void SimpleTest()
{
CString Connect;
const LPCTSTR c_Prov = "Provider=";
const LPCTSTR c_JetProvider = "Microsoft.Jet.OLEDB.4.0";
const LPCTSTR c_DS = "Data Source=";
const LPCTSTR c_DbName = "C:\\TestADO.mdb";
const LPCTSTR c_Suffix = "Persist Security Info=False";
Connect.Format("%s%s; %s%s; %s;", c_Prov, c_JetProvider,
c_DS, c_DbName, c_Suffix);
HRESULT hr;
CnnPtr TheConnection;
hr = TheConnection.CreateInstance( __uuidof( ADODB::Connection ));
TheConnection->Open(LPCTSTR(Connect), "", "", NULL);
const LPCTSTR TheCommand = "Select * from Person2";
_RecordsetPtr TheRecordset;
TheRecordset.CreateInstance( __uuidof( ADODB::Recordset ));
TheRecordset->Open(TheCommand,
_variant_t((IDispatch *) TheConnection, true),
ADODB::adOpenStatic,
ADODB::adLockPessimistic,
1);
TheRecordset->MoveFirst();
FieldsPtr TheFields = TheRecordset->GetFields();
TRACE("\n\nBegin Test\n\n");
for (int counter = 0; counter < 3; ++counter)
{
_variant_t vtTooLarge
("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
try
{
TheFields->GetItem("LastName")->PutValue(vtTooLarge);
TRACE("TooLarge worked\n");
}
catch(_com_error &e)
{
TRACE("Too Large Set Failed %X\n%s\n",
e.Error(), (char *) e.Description());
}
_variant_t vtJustRight("aaa");
try
{
TheFields->GetItem("LastName")->PutValue(vtJustRight);
TRACE("JustRight worked\n");
}
catch(_com_error &e)
{
TRACE("Just Right Set Failed %X\n%s\n",
e.Error(), (char *) e.Description());
}
TRACE("\n");
}
TRACE("Test Complete\n\n");
try
{
TheRecordset->Update();
}
catch(_com_error &e)
{
TRACE("Update Failed %X\n", e.Error());
}
try
{
TheRecordset->CancelUpdate();
}
catch(_com_error &e)
{
TRACE("CancelUpdate Failed %X\n", e.Error());
}
try
{
TheRecordset->Close();
}
catch(_com_error &e)
{
TRACE("Rst Close Failed %X\n", e.Error());
}
try
{
TheConnection->Close();
}
catch(_com_error &e)
{
TRACE("Cnn Close Failed %X\n", e.Error());
}
}
**************TRACE OUTPUT ********************
Begin Test
Too Large Set Failed 80040E21
The field is too small to accept the amount of data you attempted to add.
Try inserting or pasting less data.
JustRight worked
Too Large Set Failed 80040E21
The field is too small to accept the amount of data you attempted to add.
Try inserting or pasting less data.
Just Right Set Failed 80040E21
Update or CancelUpdate without AddNew or Edit.
Too Large Set Failed 80040E21
Update or CancelUpdate without AddNew or Edit.
Just Right Set Failed 80040E21
Update or CancelUpdate without AddNew or Edit.
Test Complete
- Next message: Bill Thompson: "Re: Problem with ADO"
- Previous message: Joshua Weir: "Re: Change the name of my application"
- Next in thread: Bill Thompson: "Re: Problem with ADO"
- Reply: Bill Thompson: "Re: Problem with ADO"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|