Hello Axel,
Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.
Based on the test in my side, I can create a new Transaction using
connection.BeginTransaction after the previous one is committed. It does
not pop up any exception to me. The codes in my side look like,
private static void ExecuteSqlTransaction(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
SqlTransaction transaction;
//First Time
transaction = connection.BeginTransaction("SampleTransaction");
command.Connection = connection;
command.Transaction = transaction;
try
{
command.CommandText =
"Insert into People (Id, Name) VALUES (1,
'Colbert')";
command.ExecuteNonQuery();
command.CommandText =
"Insert into People (Id, Name) VALUES (2, 'Erika')";
command.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception ex)
{
Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
Console.WriteLine(" Message: {0}", ex.Message);
try
{
transaction.Rollback();
}
catch (Exception ex2)
{
Console.WriteLine("Rollback Exception Type: {0}",
ex2.GetType());
Console.WriteLine(" Message: {0}", ex2.Message);
}
}
//Second Time
transaction = connection.BeginTransaction("SampleTransaction");
command.Connection = connection;
command.Transaction = transaction;
try
{
command.CommandText =
"Insert into People (Id, Name) VALUES (3, 'Grace')";
command.ExecuteNonQuery();
command.CommandText =
"Insert into People (Id, Name) VALUES (4, 'Emmy')";
command.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception ex)
{
Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
Console.WriteLine(" Message: {0}", ex.Message);
try
{
transaction.Rollback();
}
catch (Exception ex2)
{
Console.WriteLine("Rollback Exception Type: {0}",
ex2.GetType());
Console.WriteLine(" Message: {0}", ex2.Message);
}
}
}
}
Currently, the best guess of this issue you described is the parallel
transaction. When your query returns a large amount of data and then calls
BeginTransaction, a SqlException is thrown because SQL Server 2005 does not
allow parallel transactions when using MARS. To avoid this problem, always
associate a transaction with the command, the connection, or both before
any readers are open. This information is documented here
http://msdn.microsoft.com/en-us/library/5ha4240h.aspx.
Please let me know if this fixes the issue in your side.
Best regards,
Ji Zhou (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications..
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.