Unexpected results from forcing the ChangeTo
"Alan R. Parker" <[email protected]> Thu, 27 Feb 2003 08:31:34 -0800
| Newsgroups | gmane.comp.windows.devel.oledb.devel |
|---|---|
| Message-ID | <OLEDB_DEV%[email protected]> |
I've got a worker function which having completed an insert does the
following:
//to get the id of the field, requery the database with the @@IDENTITY
string
_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;
// having done the insert...
_bstr_t bstrQuery("SELECT @@IDENTITY");
//create a recordset to hold the queried data which is the identity
adoRS->Open(_variant_t(bstrQuery), vNull ,
ADODB::adOpenStatic, ADODB::adLockBatchOptimistic,
ADODB::adCmdText );
_variant_t vID;
vID = adoRS->GetCollect(L"");
//vID.ChangeType(VT_I4); // hangs here
*lPrimaryKey = vID.lVal;
//close the recordset
adoRS->Close();
Now given the schema of some of my database tables, it seems I don't always
expect, in this worker, to get a valid vID.lVal back - if I actually call
ChangeTo on the vID.lVal, against SQLServer2000SP3, the com+ server hangs,
the database has outstanding locks, and eventually the (scripting) clients
time out, or if I shutdown the calling object, the system sorts itself out.
Now these #imported calls are inside a try catch which I'd have expected to
fire, seems it doesn't .. if I put a simple local catch all around the
vID.ChangeType(VT_I4) then I get to continue without hanging.
Now I appreciate that ChangeType might be failing based on the actual table
that the generic function as called to act against, but I'm loathe to
remove the explicit coersion...
Arp
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.