Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reuse an Existing Connection String in my SQL Session State Config?

I'm using SQL Session State in my app, however given that we have several connection strings already, it would be easier to maintain the config if all the connection strings were held, well, in <connectionStrings>.

My question is, is it possible somehow to specify an existing connection string in the sessionState config?

   <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>
like image 812
StuartLC Avatar asked Jul 12 '12 06:07

StuartLC


1 Answers

Anyone coming to this late the MSDN documentations state that for the sqlConnectionString attribute you can specify either the full connection string OR the name of an existing connection string: https://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=vs.85%29.aspx (see sqlConnectionString under Attributes & Elements)

like image 151
Reuben Greaves Avatar answered Sep 20 '22 12:09

Reuben Greaves