TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abdalla Omran
NA
334
32.4k
This SqlTransaction has completed; it is no longer usable ?
Jan 1 2020 10:06 AM
I am facing a problem with sqlbulk .
I have a list of PersonModel and trying to insert or save the data into SQL server but i am getting an exeption
private static List<PersonModel> PersonModels { get; set; }
AsDataTable is an Extention Method
its throwing an exception on transaction.Commit().... System.InvalidOperationException "This SqlTransaction has completed; it is no longer usable "
using
(SqlConnection connection =
new
SqlConnection(CS))
{
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
using
(var bulkCopy =
new
SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName =
"dbo.Person"
;
try
{
bulkCopy.WriteToServer(PersonModels.AsDataTable());
}
catch
(Exception ex)
{
transaction.Rollback();
Console.WriteLine(
"Rollback Exception Type: {0}"
, ex.GetType());
Console.WriteLine(
" Message: {0}"
, ex.Message);
}
}
transaction.Commit();
}
Reply
Answers (
1
)
five Real time examples for sbyte dot.net
Parallel.ForEach (is there any thing more faster) ?!