2017-04-25 7 views
5

हमें सत्र संदर्भ मानों को सेट करने और साफ़ करने में समस्याएं हैं। The value was not set for key X because the total size of keys and values in the session context would exceed the 1 MB limitएसक्यूएल सर्वर सत्र संदर्भ सीमा

हम अपने डेटा का उपयोग के लिए asp.net कोर और व्यवसायिक उपयोग कर रहे हैं:

हम निम्न त्रुटि प्राप्त।

कनेक्शन खोलते समय हम sp_set_session_context निष्पादित करते हैं और 4 कुंजी भेजते हैं। 3 जो पूर्णांक हैं और 1 जो एक स्ट्रिंग है।

स्ट्रिंग परीक्षण में रिक्त है और पूर्णांकों एक एसक्यूएल आदेश हम तो, शून्य के करीब है, और कनेक्शन के निपटान सत्र संदर्भ मूल्यों को निर्धारित क्रियान्वित करने के बाद कम से कम 10

हैं। यही कारण है कि क्वेरी है SELECT SUM([pages_kb]) FROM [sys].[dm_os_memory_cache_counters] WHERE [type] = 'CACHESTORE_SESSION_CONTEXT'

अभी तक 1 एमबी से अधिक होने की:

हम निम्नलिखित क्वेरी स्मृति उपयोग को देखने के लिए उपयोग कर रहे हैं।

क्या कोई जानता है कि हमें यह त्रुटि क्यों प्राप्त हो रही है?

+0

क्या आपने [एमएसडीएन दस्तावेज़ीकरण- sp_set_session_context] पढ़ा है (https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-set- सत्र-context-transact- एसक्यूएल) विशेष समारोह – MethodMan

+0

@MethodMan हाँ मेरे पास है। – Jacob

उत्तर

4

यह एक बग है। निम्न स्क्रिप्ट मज़बूती से उस पर पुन: पेश होगा एसक्यूएल सर्वर 2017 CU3 (लेखन के रूप में):

bool unset = true; 
using (var command = new SqlCommand()) { 
    command.CommandText = "sp_set_session_context"; 
    command.CommandType = CommandType.StoredProcedure; 
    command.Parameters.Add("@key", SqlDbType.NVarChar, 128); 
    command.Parameters.Add("@value", SqlDbType.Variant, -1); 
    for (int cycles = 0; cycles != 10; ++cycles) { 
    ++cycles; 
    using (var connection = 
     new SqlConnection(@"Data Source=(localdb)\MSSqlLocalDB;Integrated Security=SSPI") 
    ) { 
     connection.Open(); 
     // Set as many values as we can 
     int keys = 0; 
     while (true) { 
     command.Connection = connection; 
     command.Parameters["@key"].Value = keys.ToString(); 
     command.Parameters["@value"].Value = new String(' ', 8000); 
     try { 
      command.ExecuteNonQuery(); 
      ++keys; 
     } catch (SqlException e) { 
      Console.WriteLine("Failed setting at {0}: {1}", keys, e.Message); 
      break; 
     } 
     } 
     if (unset) { 
     // Now unset them 
     for (; keys >= 0; --keys) { 
      command.Connection = connection; 
      command.Parameters["@key"].Value = keys.ToString(); 
      command.Parameters["@value"].Value = DBNull.Value; 
      try { 
      command.ExecuteNonQuery(); 
      } catch (SqlException e) { 
      Console.WriteLine("Failed unsetting at {0}: {1}", keys, e.Message); 
      break; 
      } 
     } 
     } 
    } 
    } 
} 

आउटपुट:

Failed setting at 125: The value was not set for key '125' because the total size of keys and values in the session context would exceed the 1 MB limit.
Failed setting at 120: The value was not set for key '120' because the total size of keys and values in the session context would exceed the 1 MB limit.
Failed setting at 115: The value was not set for key '115' because the total size of keys and values in the session context would exceed the 1 MB limit.
Failed setting at 110: The value was not set for key '110' because the total size of keys and values in the session context would exceed the 1 MB limit.
Failed setting at 105: The value was not set for key '105' because the total size of keys and values in the session context would exceed the 1 MB limit.

उपलब्ध संदर्भ आकार हर चक्र के साथ कम हो जाती है। यदि लंबे समय तक जारी रहता है, तो यह कुछ न्यूनतम मूल्य (आवश्यक रूप से 0) तक गिर जाएगा। इस बिंदु पर, sys.dm_os_memory_cache_counters से पूछताछ से पता चलता है कि उपयोग में 1 एमबी से भी कम है, लेकिन फिर भी, कोई सत्र संदर्भ सेट नहीं किया जा सकता है।

कामकाज सरल है: जब आप पूरा कर लें तो मानों को NULL पर सेट न करें, इंजन को बाहर निकालने के लिए छोड़ दें। उपर्युक्त स्क्रिप्ट में, यदि आप unset से false पर सेट करते हैं, तो आप कोई सत्र संदर्भ लीक होने का निरीक्षण नहीं करेंगे।

मैं पर माइक्रोसॉफ्ट कनेक्ट, जो समाप्त हो चुकी है इस पोस्ट किया है - मुद्दा User Voice में है, कम से कम जब तक वे बातें फिर से चारों ओर ले जाने का फैसला। दुर्भाग्य से उन्होंने बग रिपोर्ट से सभी विवरणों को काट दिया है, लेकिन इस सवाल का लिंक बना हुआ है।

+0

धन्यवाद! उम्मीद है कि वे जल्द ही बग को संबोधित करेंगे – Jacob

+0

रिपोर्टिंग के लिए बहुत बहुत धन्यवाद। आज के रूप में, यह तय नहीं है। मेरा कामकाज शून्य के बजाए एक अमान्य मान को स्टोर करना है। –

संबंधित मुद्दे