Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Web.config with variable or key inside

Web.config with variable or key inside

Scheduled Pinned Locked Moved ASP.NET
securityquestionworkspace
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marius DUMITRU
    wrote on last edited by
    #1

    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 ??

    S K 2 Replies Last reply
    0
    • M Marius DUMITRU

      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 ??

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      • M Marius DUMITRU

        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 ??

        K Offline
        K Offline
        Karthik A
        wrote on last edited by
        #3

        Why not just do this ?

        As Sandeep said, you cannot have programming logic w/in your web.config file.

        Cheers, Karthik

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups