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. Use different web.config for debugging

Use different web.config for debugging

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
4 Posts 3 Posters 0 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.
  • E Offline
    E Offline
    error1408
    wrote on last edited by
    #1

    I'd like to use a different web.config for debugging my webapplication at my local machine, without renaming or sth. Is there a way to do this? The reason is I don't wanna use the same strange database names etc. for my local database like the ones generated by my webhoster. I also would like to use different passwords. (My connectionString is stored in the web.config) Hope somebody can help me.

    N F 2 Replies Last reply
    0
    • E error1408

      I'd like to use a different web.config for debugging my webapplication at my local machine, without renaming or sth. Is there a way to do this? The reason is I don't wanna use the same strange database names etc. for my local database like the ones generated by my webhoster. I also would like to use different passwords. (My connectionString is stored in the web.config) Hope somebody can help me.

      N Offline
      N Offline
      nateraaaa
      wrote on last edited by
      #2

      You could get around this by creating a testing section (development) with your connectionString and a production section with your webhoster connectionString in your web.config. When you are testing locally just comment out the production section and uncomment the development section. When you are done testing locally and are ready for production comment the development section and uncomment the production section. Nathan

      E 1 Reply Last reply
      0
      • N nateraaaa

        You could get around this by creating a testing section (development) with your connectionString and a production section with your webhoster connectionString in your web.config. When you are testing locally just comment out the production section and uncomment the development section. When you are done testing locally and are ready for production comment the development section and uncomment the production section. Nathan

        E Offline
        E Offline
        error1408
        wrote on last edited by
        #3

        Thats what i'm doing at the moment, but it's time consuming if you have to do it several times. Is there no other way?

        1 Reply Last reply
        0
        • E error1408

          I'd like to use a different web.config for debugging my webapplication at my local machine, without renaming or sth. Is there a way to do this? The reason is I don't wanna use the same strange database names etc. for my local database like the ones generated by my webhoster. I also would like to use different passwords. (My connectionString is stored in the web.config) Hope somebody can help me.

          F Offline
          F Offline
          Fred_Smith
          wrote on last edited by
          #4

          I never understand why people save their connection strings in web.config... how unsecure is that? This is how I avoid your problem: 1) In global.asax I have a function like this: Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Select Case Server.MachineName.ToLower Case "aaaaa" ' local Application("ServerName") = "local" Case "bbbbb" ' laptop Application("ServerName") = "laptop" Case Else ' ' live Application("ServerName") = "live" End Select End Sub You will need to find out, if you don't know already, your local machines name. User Server.MachineName in any aspx page to find out if you need to. 2) I then make a publicly available function such this: Public Class myFunctions Public Function dbConnection(ByVal ServerName As String) As String Select Case ServerName Case "live" Return "data source=xxxxx;initial catalog=xxxxx;uid=xxxxx;pwd=xxxxx" Case "local" Return "data source=yyyyy;initial catalog=yyyyy;uid=yyyyyy;pwd=yyyyyy" Case "laptop" Return "data source=zzzzzz;initial catalog=zzzzz;uid=zzzzz;pwd=zzzzz" End Select End Function End Class 3) Then I can use the same code throught my app to connect to the database on whateve computer I am running on: Dim myFunction As New myFunctions Dim objConn As New SqlClient.SqlConnection objConn.ConnectionString = myFunction.dbConnection(Application("ServerName")) Works a treat! -- modified at 15:11 Tuesday 28th August, 2007 Of course, you don't acually need to use the Application object at all, but could call the function directly with objConn.ConnectionString = myFunction.dbConnection(Server.MachineName) if you replaced the Select..Case in the dbConnection function with the amchine names there instead of the aliases I created. But there was a reason I did it this way when I first came up with it - just can't remember what it was now! - and I have always done it the same way since! Fred

          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