Retrieving the connection string from web.confi
-
I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you
-
I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you
-
I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you
If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page
-
If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page
And how will this improve things? What happens when a connection string is updated in the webconfig?
I know the language. I've read a book. - _Madmatt
-
I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you
you can use the following code........in C#.net either put your connection string in web.config under appsettings/connections string section using System.Configuration; public static string ConnectionString { get { //return ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); return ConfigurationManager.AppSettings["ConnectionString"].ToString(); } }
-
you can use the following code........in C#.net either put your connection string in web.config under appsettings/connections string section using System.Configuration; public static string ConnectionString { get { //return ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); return ConfigurationManager.AppSettings["ConnectionString"].ToString(); } }
Did even bother to read the original post?
I know the language. I've read a book. - _Madmatt
-
you can add your connectionstring or userid to session at login page and use the session in another pages
MHFARDAD
Thanx Hussain. As you said, i used Session variable to get the connectionstring.
-
If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page
Thanx Mr.Biswas. I did fix the problem with session object. But I will keep in my mind your suggesiton and I will use it in the other module. Thank you Prasad