473,434 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

CDatabase Transactions

Hi all,

Have a quick question. I have an app that connects to SQL Server via the
MFC CDatabase class. I'm doing bulk loading using the ODBC bulk opns
extensions for SQL Server. When I try to wrap my bulk inserts in a
transaction using BeginTrans() and CommitTrans(), it doesn't work. When I
use SQLExecDirect() and send a T-SQL "BEGIN TRANSACTION" and "COMMIT
TRANSACTION", it does work.

I was just wondering if there's something peculiar about MFC CDatabase
transaction that keep the BeginTrans() and CommitTrans() from working
correctly with ODBC bulk operations. Also, I was told that I shouldn't use
SQLExecDirect() to execute the T-SQL BEGIN TRANSACTION and COMMIT
TRANSACTION statements. Is this true?

Thanks
Jun 27 '06 #1
3 1947
BTW - it looks to me as if the rationale for not sending T-SQL statements to
begin and commit a transaction is in case your driver doesn't support it. I
can't find any other reason not to... And my driver is guaranteed to
support it, so I'm at a loss for reasons not to?

Thanks

"Mike C#" <xy*@xyz.com> wrote in message
news:uN**************@TK2MSFTNGP02.phx.gbl...
Hi all,

Have a quick question. I have an app that connects to SQL Server via the
MFC CDatabase class. I'm doing bulk loading using the ODBC bulk opns
extensions for SQL Server. When I try to wrap my bulk inserts in a
transaction using BeginTrans() and CommitTrans(), it doesn't work. When I
use SQLExecDirect() and send a T-SQL "BEGIN TRANSACTION" and "COMMIT
TRANSACTION", it does work.

I was just wondering if there's something peculiar about MFC CDatabase
transaction that keep the BeginTrans() and CommitTrans() from working
correctly with ODBC bulk operations. Also, I was told that I shouldn't
use SQLExecDirect() to execute the T-SQL BEGIN TRANSACTION and COMMIT
TRANSACTION statements. Is this true?

Thanks

Jun 27 '06 #2
> Have a quick question. I have an app that connects to SQL Server via the
MFC CDatabase class. I'm doing bulk loading using the ODBC bulk opns
extensions for SQL Server. When I try to wrap my bulk inserts in a
transaction using BeginTrans() and CommitTrans(), it doesn't work. When I
use SQLExecDirect() and send a T-SQL "BEGIN TRANSACTION" and "COMMIT
TRANSACTION", it does work.

I was just wondering if there's something peculiar about MFC CDatabase
transaction that keep the BeginTrans() and CommitTrans() from working
correctly with ODBC bulk operations. Also, I was told that I shouldn't
use SQLExecDirect() to execute the T-SQL BEGIN TRANSACTION and COMMIT
TRANSACTION statements. Is this true?


There are good reasons not to run bulk insert into a context of a
transaction. This can lead to a table and a database locks, and can produce
enormous logs. You may consider creating a SP, which BULK INSERTs into the
temporary tables, and then inserts data into destination tables. A careful
design allows to reconstruct a big transaction into series of small ones.
--
Vladimir Nesterovsky
Jun 27 '06 #3

"Vladimir Nesterovsky" <vl******@nesterovsky-bros.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
There are good reasons not to run bulk insert into a context of a
transaction. This can lead to a table and a database locks, and can
produce enormous logs. You may consider creating a SP, which BULK INSERTs
into the temporary tables, and then inserts data into destination tables.
A careful design allows to reconstruct a big transaction into series of
small ones.


I'm not using the T-SQL BULK INSERT statement, I'm using the ODBC Bulk
Operations API from C++. I've set it up to use minimal logging (no indexes,
etc.) I've gone down the bulk insert to temp table ---> copy to real table
routine, and the logging is a lot larger + the speed is a lot slower than
just bulk inserting into the table. Basically I can bulk load 50,000 rows
in about 29 seconds, which is about an hour and a half of improvement over
the previous method that was being used to push this data in. The bulk
inserting is occurring late at night, when no one is using the system so
table locking is not an issue. I'm not too concerned about deconstructing
this into a smaller series of transactions. Basically I just need to know
if there is any reason not to use T-SQL BEGIN TRANS and COMMIT TRANS
statements instead of CDatabase methods.

Thanks.
Jun 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nilesh | last post by:
Hello, I am using MFC classes Cdatabase & Crecordset to open the data source & do all the updates, everything seems to be working, However, as soon as I try exiting the application, it gives me...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
1
by: | last post by:
Dear All, I am trying to use CDatabase class and include the class <afxdb.h>, but the following error occurs, Linking... nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator...
9
by: Mike C# | last post by:
Hi all, 'Nother question. I have a piece of code that is using the MFC CDatabase object to connect to a database. It executes a SQL statement against SQL Server using the ExecuteSQL()...
12
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic...
1
by: karol1208 | last post by:
I use method ExecuteSQL (CDatabase class) to execute the query like this: "DECLARE @p3 int EXEC myfunction 'mytable', 1, @p3 output select @p3". The query is executed currently - the data base...
1
by: magix | last post by:
Hi, I'm using Visual C++ and doing INSERT process into mdb file May I know if it is possible to use Absolute path to specifiy mdb file ? where mdb file is at the same directory as the...
4
by: navraj | last post by:
Hi Evreybody I am trying to use the CDatabase class in my dll to connect to SQL but it keeps throwing me an error "CDatabase is not a class or namespcae" or the error "CDataBase : base class...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.