asp.net - Dynamic Connecton String Based on Session Variable -


I have an application that launches data for my client over a period of time, the client is called 'play' wide To allow other scenarios to mess up production data, they can choose an alternative database (basically what-if scenario) at any point, which is a copy of the production database At a certain time currently, I have There is a bit of code which The connection replacement string to string, which will hot-swap server name and the database name on the basis of the stored user session state.

This approach works well for what I'm doing, although I need to cross those selections at every level. My question is: Would I be able to create a custom connection string which handles this 'switching' in the background and allows me to use a string like I do in the standard ASP.Net application.

In other words, many asp.net tools accept only a connection string name as part of its manufacturer. I want to be able to use those tools, but the way I currently create my connection string, I can not do B / C. Is there a way to support this behavior at user session level?

Working with it.

Some people have their own web Complete copies of config files (where connection strings should be kept) and using Post-Build events, they can copy a relevant web.config file based on the "Release Configuration" that you can use in Visual Studio Are there.

This method is also Scott Gu. Besides this, see this stack overlow question:

Now, there are very good ways, initially ASP.NET applications deployed , if You want to do this, when this application is already posted you can use this functioning mechanism:

It looks like you are already doing something like this , And if you want to dynamically switch the database in a timely manner, then I think you can Can also be simply attributed to "switch" the connection string in the Y provide our Code Of course, here's the trick to make it easier so that the database connection string is only one place in your application for the rest of your application. Perhaps the best way to handle it is to make sure that all the values ​​you want to get from web.config are obtained using the class obtained from the class. It is necessary for you to "switch" any argument (such as "connection string-based-on-machine-name" moves) back to a real value, and you can use "connectionstring" of your custom class Will allow to allow "the property in the constructor of any other component is required, for which the connection string needs to be changed as a parameter, when it is connected to the actual connection Writing value changes.

There are some good resources for custom configuration sections:




Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -