filmov
tv
ConnectionString inside webConfig File

Показать описание
Connection String inside webConfig File
It is an XML document that resides in the root directory of the site or application and
contains data and Settings about how the web application will act.
And one of the usefull usage of it is you can store your connectio string inside one of its
In real time senario you use your local connection String while you still building your web application
and change it again to Server connection String .
But what will happen if you modify and update your website from time to time, specially if you have multi pages.
it will time consuming if every time you have to change the connection string from local to the server one.
What i will show right now is how to conteniu working with your application
without bothering your self with changing your connection string.
so the main different but your local app and you server app is your domain but the pages is offcourse the same.
so all what you have to do is check your URL if it contains localhost or not "simple" .
using Request.Url.Host. Just add the following lines to your page load event
//string connString = "";
//if (Request.Url.Host.Contains("local"))
//{
// connString = "LocalConnectionString";
//}
//if (Request.Url.Host.Contains("feel"))
//{
// connString = "ServerConnectionString";
//}
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings[connString].ConnectionString;
It is an XML document that resides in the root directory of the site or application and
contains data and Settings about how the web application will act.
And one of the usefull usage of it is you can store your connectio string inside one of its
In real time senario you use your local connection String while you still building your web application
and change it again to Server connection String .
But what will happen if you modify and update your website from time to time, specially if you have multi pages.
it will time consuming if every time you have to change the connection string from local to the server one.
What i will show right now is how to conteniu working with your application
without bothering your self with changing your connection string.
so the main different but your local app and you server app is your domain but the pages is offcourse the same.
so all what you have to do is check your URL if it contains localhost or not "simple" .
using Request.Url.Host. Just add the following lines to your page load event
//string connString = "";
//if (Request.Url.Host.Contains("local"))
//{
// connString = "LocalConnectionString";
//}
//if (Request.Url.Host.Contains("feel"))
//{
// connString = "ServerConnectionString";
//}
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings[connString].ConnectionString;