Connection page and how to call it
Hello to all,
In old classic asp, I use sql server connection in .asp page, then I use
< ! -- # include file="mysqldb.asp" - - >
In above page if the connection is not valid then direct user to error page.
Can someone help me to accomplish this in C#.
I need know how to create similar technique and how to call it from another C# page
Thank you in advance

Roei BarRank #1,271 · 1.4K reputationPosted Aug 2, 2009, 12:19 PM EDT
i could offer you several options,
you could either add a global.asa file and on sessionstart check that that you have a connection to db and otherwise redirect to error.
you could also just put a default error page and set on web.config that on every error you throw the user to that page, and throw exception if you have no connection to the db.
i dont know exactly what you need todo , but if you have to keep db connection, i would work with a masterpage and on the master make sure that on the Onload event i will have a db checkup fuction, this will make us redirect to errorpage, on all other "ContentPages".
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 2, 2009, 9:16 PM EDT
You can specify your database connection string in web.cofig like below:
Now if you want to retrieve it in your page use the following code in your page behind (Using c#):
string STRConnectionstring = ConfigurationManager.AppSettings["WebsiteDBConnectionString"].ToString();
For CustomErrors page you can have a common error page and use it in web.config like this:
linda6 reputationPosted Aug 3, 2009, 5:21 AM EDT
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 3, 2009, 6:17 AM EDT
Using web.config is absolutely safe and secure. Still if you have any doubts then you can encrypt the connection string details in web.config.
Roei BarRank #1,271 · 1.4K reputationPosted Aug 3, 2009, 6:33 AM EDT
Please remember to click "Do you like this answer" on the post that helps you.