2012-03-15 49 views
1

使用無論是隔離級別,也沒有加強它支持

Microsoft SQL Server 2008 (SP1)

試圖創建出象這樣的交易:

OleDbConnection con; 
OleDbTransaction transaction = null; 
... 
transaction = con.BeginTransaction(IsolationLevel.Snapshot); 

而得到錯誤:

System.Data.OleDb.OleDbException (0x8004D008): Neither the isolation level nor a strengthening of it is supported. 
    at System.Data.OleDb.OleDbTransaction.ProcessResults(OleDbHResult hr) 
    at System.Data.OleDb.OleDbTransaction.BeginInternal(ITransactionLocal 

transaction) at System.Data.OleDb.OleDbConnectionInternal.BeginTransaction(IsolationLevel isolationLevel) at System.Data.OleDb.OleDbConnection.BeginTransaction(IsolationLevel isolationLevel)

我確信在SQL Server Management Studio中運行以下代碼:

ALTER DATABASE mydb SET SINGLE_USER WITH ROLLBACK IMMEDIATE; 
ALTER DATABASE mydb SET ALLOW_SNAPSHOT_ISOLATION ON; 
ALTER DATABASE mydb SET READ_COMMITTED_SNAPSHOT ON; 
ALTER DATABASE mydb SET MULTI_USER; 

我錯過了什麼?

+2

或者,在開始交易之前執行SQL命令? – Oded 2012-03-15 19:44:39

回答

2

用SqlClient替換OleDb(如評論中建議的Oded)。如果您在使用SQL Server爲什麼不使用SQL Server提供的,而不是OLEDB

SET TRANSACTION ISOLATION LEVEL SNAPSHOT; 
+0

使用sql語句結束,目前使用OLEDB,因爲相同的代碼支持Oracle,Sybase ASE和MSSQL。感謝Anthony和Oded的幫助 – Alex 2012-03-16 02:17:12