का निपटान करने के बाद अलगाव स्तर को वापस नहीं करता है मैं लेनदेन के क्षेत्र और इकाई ढांचे के साथ थोड़ा सा सरगर्मी कर रहा हूं।एंटीटी फ्रेमवर्क और ट्रांस्पेक्शनस्कोप लेनदेनकोप
प्रारंभ में हम डेटा पढ़ने के दौरान स्नैपशॉट अलगाव स्तर का उपयोग करने के लिए एप्लिकेशन में हमारे सभी कनेक्शन चाहते हैं, लेकिन कुछ परिस्थितियों में हम या तो पढ़ने के लिए डेटा पढ़ना चाहते हैं या असामान्य अलगाव स्तर पढ़ना चाहते हैं और इसके लिए हम लेनदेन के क्षेत्र को बदलने के लिए उपयोग करेंगे अलगाव स्तर प्रश्नों के लिए अस्थायी है (जैसा कि यहां और विभिन्न ब्लॉगों में कई पदों में बताया गया है)।
हालांकि, समस्या यह है कि जब लेनदेन के दायरे का निपटारा किया जाता है, तो अलगाव अभी भी कनेक्शन पर बना रहता है, जिससे काफी समस्याएं होती हैं।
मैंने सभी प्रकार की विविधताओं का प्रयास किया है, लेकिन उसी परिणाम के साथ; अलगाव लेनदेन लेनदेन के दायरे से परे संरक्षित है।
क्या कोई ऐसा व्यक्ति है जो मेरे लिए इस व्यवहार को समझा सकता है या समझा सकता है कि मैं क्या गलत कर रहा हूं?
मुझे एक डिस्पोजेबल क्लास के भीतर लेनदेन के दायरे को समाहित करके समस्या के लिए एक समाधान मिला है जो मेरे लिए अलगाव स्तर को उलट देता है, लेकिन मैं इस व्यवहार पर एक अच्छी व्याख्या की सराहना करता हूं, मुझे लगता है कि यह व्यवहार न केवल प्रभावित करता है मेरा कोड, लेकिन अन्य भी।
यहाँ एक examplecode है कि समस्या को दिखाता है:
using (var context = new MyContext())
{
context.Database.Connection.Open();
//Sets the connection to default read snapshot
using (var command = context.Database.Connection.CreateCommand())
{
command.CommandText = "SET TRANSACTION ISOLATION LEVEL SNAPSHOT";
command.ExecuteNonQuery();
}
//Executes a DBCC USEROPTIONS to print the current connection information and this shows snapshot
PrintDBCCoptions(context.Database.Connection);
//Executes a query
var result = context.MatchTypes.ToArray();
//Executes a DBCC USEROPTIONS to print the current connection information and this still shows snapshot
PrintDBCCoptions(context.Database.Connection);
using (var scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions()
{
IsolationLevel = IsolationLevel.ReadCommitted //Also tried ReadUncommitted with the same result
}))
{
//Executes a DBCC USEROPTIONS to print the current connection information and this still shows snapshot
//(This is ok, since the actual new query with the transactionscope isn't executed yet)
PrintDBCCoptions(context.Database.Connection);
result = context.MatchTypes.ToArray();
//Executes a DBCC USEROPTIONS to print the current connection information and this has now changed to read committed as expected
PrintDBCCoptions(context.Database.Connection);
scope.Complete(); //tested both with and without
}
//Executes a DBCC USEROPTIONS to print the current connection information and this is still read committed
//(I can find this ok too, since no command has been executed outside the transaction scope)
PrintDBCCoptions(context.Database.Connection);
result = context.MatchTypes.ToArray();
//Executes a DBCC USEROPTIONS to print the current connection information and this is still read committed
//THIS ONE is the one I don't expect! I expected that the islation level of my connection should revert here
PrintDBCCoptions(context.Database.Connection);
}
कुछ उत्तरों में भी उल्लेख किया गया है [_here _] (http : //stackoverflow.com/questions/3759897/how-does-sqlconnection-manage-isolationlevel) और संभावित रूप से संबंधित [_Connect Bug_] (https://connect.microsoft.com/SQLServer/feedback/details/243527/sp- रीसेट-कनेक्शन-does not को रीसेट-अलगाव-स्तर)। – crokusek