Web.config with variable or key inside
-
Hello. Is it possible to achive this: (all is inside web.config) <configuration> <appSettings> <add key="strSQLServer" value="srvproduction\SQL2008Express"> </appSettings> <connectionStrings> <add name="dbConn" connectionString="Data Source=" + key["strSQLServer"] + ";MultipleActiveResultSets=True;Initial Catalog=db1;Persist Security Info=True;Connection Timeout=600;User ID=sa;Password=***" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> Like I said at the begining: all is inside web.config ??
-
Hello. Is it possible to achive this: (all is inside web.config) <configuration> <appSettings> <add key="strSQLServer" value="srvproduction\SQL2008Express"> </appSettings> <connectionStrings> <add name="dbConn" connectionString="Data Source=" + key["strSQLServer"] + ";MultipleActiveResultSets=True;Initial Catalog=db1;Persist Security Info=True;Connection Timeout=600;User ID=sa;Password=***" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> Like I said at the begining: all is inside web.config ??
Marius DUMITRU wrote:
Is it possible to achive this: (all is inside web.config) connectionString="Data Source=" + key["strSQLServer"] + ";MultipleActiveResultSets=True;
No. Not possible. Web.Config is application's configuration file and not a programming logic in itself. You can maximum write in web.config file but it will not evaluate things in it by itself. It's a simple config file. Last but not the least, what you ask is not needed - I don't think there is any reason to have/do it like this. Config file is the way to provide defined connection string. If you want multiple datasource, then just define multiple connection strings. Refer: MSDN: connectionStrings Element (ASP.NET Settings Schema)[^]
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Hello. Is it possible to achive this: (all is inside web.config) <configuration> <appSettings> <add key="strSQLServer" value="srvproduction\SQL2008Express"> </appSettings> <connectionStrings> <add name="dbConn" connectionString="Data Source=" + key["strSQLServer"] + ";MultipleActiveResultSets=True;Initial Catalog=db1;Persist Security Info=True;Connection Timeout=600;User ID=sa;Password=***" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> Like I said at the begining: all is inside web.config ??