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