0
我有一個與SQL Server 2000和SQL Server 2008ADO.Net的交易連接到SQL Server 2000和SQL Server 2008的差異
SqlConnection con = new SqlConnection("connecstionstring");
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MySp";
con.Open();
SqlTransaction trans = con.BeginTransaction();
cmd.Transaction = trans;
cmd.ExecuteNonQuery();
trans.Commit();// this step will fail with sql server 2008 but success with 2000
con.Close();
和SP代碼的作用不同一些C#/ ado.net代碼如:
ALTER PROCEDURE MySp
AS
BEGIN
COMMIT --this match the outside 'begin trans' in c# code
do some thing...
BEGIN TRANSACTION -- this match the outside 'commit' in c# code
END
當連接到SQL Server 2008,C#代碼將無法在 'trans.Commit()',和異常說:交易已經COMMITED,不能再使用。
但連接到SQL Server 2000,它會成功。請告訴我爲什麼?