Connecting to IBM DB2 via Visual C++ 2010/ADO connection.
I'm creating a program that moves files after adding/updating lines.
I tried to roll back when the file move failed, but now I'm committed.
Is there any way to turn off AutoCommit when connecting or executing DML statements?
The actual source is classified, so if you take out the relevant parts, you'll see the following:
CStringszConnection="Provider=IBMDADB2.DB2COPY1; Password=PASS; Persist Security Info=True; User ID=USER; Data Source=TESTDB; Location=xxx.xx.xxx.xx; Extended Properties="; Package Collection";
_ConnectionPtr_connection;
_connection.CreateInstance(_uuidof(Connection)));
_connection->Open(LPCTSTR) szParam, _T(""), _T("", adConnectUnspecified);
_connection->BeginTrans();
CStringszSql="*UPDATE or INSERT";
_connection->Execute(_bstr_t)szSql, &va, adOptionUnspecified);
if {
// success
_connection->CommitTrans();
} else{
// time of failure
_connection->RollbackTrans();
}
2016-06-27 Additional
in connection properties (db2cli.ini or odbc configuration file)
AutoCommit=0 or
SQL_AUTOCOMMIT_OFF
in ODBC's SqlSetAttribute
I think I can give it to you, but I don't know how to give it to you via Ado_ConnectionPtr
上記 Regarding the above problem, we tried to change the order of processing, but this is a topic that I am interested in, so I will leave it.
c++ visual-studio database mfc db2
According to BeginTrans, CommitTrans, and RollbackTrans methods,
Not all providers support transactions.Check the Properties collection of the Connection object to see if the provider-defined property "Transaction DDL" is displayed.If you see this property, the provider supports transactions.For providers that do not support transactions, invoking the transaction method results in an error.
Yes, please check _connection->Properties
.
Also
_connection->BeginTrans();
What is the return value of ? Are there any errors? By the way, 1
should be returned.This is because according to IBM OLE DB Provider limit,
IBMDADB2 supports automatic commit and user-controlled transaction scopes through the IT transactionLocal interface. The default scope is the auto-commit transaction scope. Nested transactions are not supported.
and 2
or more nested transactions are unlikely to work.
© 2024 OneMinuteCode. All rights reserved.