How do you declare or use variables in web.config

346 views Asked by At

Because our web application is using both Entityframework and System.Data.SqlClient, we need to have 2 . This is very error prone, as you need to make you update both with the same data.

So i wonder if its posible to add variables to the web.config xml?

<connectionStrings>
   <add name="Server" value="sql2014" type="variable" />
   <add name="database" value="MyDB" type="variable" />
   <add name="userName" value="sqluser" type="variable" />
   <add name="password" value="kaldsommer" type="variable" />

    <add name="XReport" connectionString="Data Source={Server};Initial Catalog={MyDB};User ID={username};Password={password}" providerName="System.Data.SqlClient" />
    <add name="XEntities" connectionString="metadata=res://*/Entities.XModel.csdl|res://*/Entities.XModel.ssdl|res://*/Entities.XModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source{Server};initial catalog={MyDB};MultipleActiveResultSets=True;App=EntityFramework;;Persist Security Info=True;User ID={username};Password={password}&quot;" providerName="System.Data.EntityClient" /> 
</connectionStrings>

1

There are 1 answers

0
EKS On BEST ANSWER

Pr @Bartude reply in comment.

FAIK, this is not possible. On the other hand maintaining 2 connection strings is not that complicated, although I agree it's always best to update things only once