473,385 Members | 2,005 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,385 software developers and data experts.

SqlBulkCopy and transactions

Hi,

I am trying to enlist an instance of SqlBulkCopy into a transaction. When I
executes and try to write to the database IŽll get an exception indicating a
transactional deadlock.

"Transaction (Process ID 58) was deadlocked on lock resources with another
process and has been chosen as the deadlock victim. Rerun the transaction."

1) Is it possible to do a cast of the transaction has I do below?
2) If the following approach is a dead end. How would you guys design a
solution? I am bound to use the transactional mechanism provided by
Enterprise Library and the already implemented way that local transactions
are created!?

The transaction used is started in the business layer of the application:

IDbConnection conn =
DatabaseFactory.CreateDatabase().CreateConnection( );
conn.Open();
IDbTransaction transaction = conn.BeginTransaction();

A controller class then manages the business case and performs operations...

Call 1 --> Delete(obj, transaction);

private void Delete(Domain obj, DbTransaction transaction)
{
DbCommand command = db.GetStoredProcCommand("DeleteDomain");
db.AddInParameter(command, "@Id", DbType.Int32, obj.Id);
db.ExecuteNonQuery(command, transaction);
}

Call 2 --> SaveBatch(obj.Data, (SqlTransaction)transaction);
//Observe the cast to SqlTransaction, the underlaying object has
however always been an SqlTransaction

private void SaveBatch(List<SomeClass> list, SqlTransaction
transaction)
{
SqlBulkCopy bulk = new SqlBulkCopy(transaction.Connection,
SqlBulkCopyOptions.Default, transaction);
CreateMappings(bulk);
bulk.WriteToServer(table);
}

Regards
/Oscar
Jun 27 '06 #1
0 4584

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

Similar topics

0
by: Roy | last post by:
For SqlBulkCopy class, is there a way to add columns that are not persisted when WriteToServer(DataTable) is called? I have information to be cache temperarily with the record and not need to be...
1
by: GB | last post by:
Hello: I am developing C# project, using ADO .NET 2.0 to connect to SQL Server 2005. I created a DataTable from scratch, and then use SqlBulkCopy to insert it into an empty table in a SQL Server...
0
by: Cwappy | last post by:
I have a class that builds a DataTable and then, when the process is exiting, tries to write that DataTable to SQL Server 2000 via the SqlBulkCopy class. I know the process is exiting because I'm...
1
by: harleedavidson | last post by:
Using SqlBulkCopy.WriteToServer to upload a datatable and getting: System.Data.SqlClient.SqlException Line 1: Incorrect syntax near 'COLLATE'. Database Server is SQL2000, database in in 6.5...
4
by: Chris | last post by:
I have created a datatable from a csv file. One of the columns is an integer which sometimes can be blank. When it is blank I add a dbnull.value to the column when I add to the datatable. This...
5
by: TheSteph | last post by:
Using : MS-SQL 2005 / .NET 2.0 / VS2005 I have two server with the same database def but different data. I would like to import data from Server2.TableA to Server1.TableA. If a row doesn't...
1
by: Dave | last post by:
I'm using the SqlBulkCopy object to bulk insert large DataTable's into SQL Server. Its working well except tables with IDENTITY columns in them. When calling...
2
by: Amar | last post by:
Hi, I need to insert a large amount of records pretty frequently through my application. The quickest way to achive this seems to be SQLBulkcopy class. I have implemented the solution using the...
1
by: Sergey Zenyuk | last post by:
In VB.net windows application I use following code implementing SqlBulkCopy import: Using connODBC As New OdbcConnection(ConnStrODBC) connODBC.Open() Dim dbcmd As New OdbcCommand(String....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.