【问题标题】:Can I reuse an Existing Connection String in my SQL Session State Config?我可以在我的 SQL 会话状态配置中重用现有的连接字符串吗?
【发布时间】:2012-07-11 20:21:15
【问题描述】:

我在我的应用程序中使用 SQL 会话状态,但是鉴于我们已经有多个连接字符串,如果所有连接字符串都保存在 <connectionStrings> 中,那么维护配置会更容易。

我的问题是,是否有可能以某种方式在 sessionState 配置中指定现有的连接字符串?

   <connectionStrings>
        <add name="ConnString1" connectionString="data source=xx;Initial Catalog=zzz;"  
             providerName="System.Data.SqlClient" />
        <add name="EFConnString" 
             connectionString="metadata=res://*/EF.csdl|res://*/EF.ssdl|res://*/EF.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxx;initial catalog=yyy;App=EntityFramework&quot;" 
             providerName="System.Data.EntityClient" />
        <add name="SessionStateConn" connectionString="data source=xx;Initial Catalog=zzz;"  
             providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <sessionState mode="SQLServer" 
                  sqlConnectionString="**SessionStateConn**" 
                  sqlCommandTimeout="30" customProvider="" ... etc
    </sessionState>

【问题讨论】:

    标签: asp.net web-config connection-string session-state


    【解决方案1】:

    不是真的。至少不是以不需要更改代码或转换配置文件的直接方式。在 ASP.NET 中出现这种不一致的原因是 SQL Server 会话状态是在 ASP.NET 的原始版本中引入的,而 connectionStrings 部分是在 2.0 版中添加的。 sessionState 标签设计者不能依赖尚未发明/交付的系统。

    【讨论】:

    • 感谢背景!
    【解决方案2】:

    任何迟到的人,MSDN 文档都指出,对于 sqlConnectionString 属性,您可以指定完整的连接字符串或现有连接字符串的名称: https://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=vs.85%29.aspx (参见 Attributes & Elements 下的 sqlConnectionString)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      相关资源
      最近更新 更多