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 BarPosted Aug 2, 2009, 4:19 PM
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".
Roei BarPosted Aug 3, 2009, 10:33 AM
Please remember to click "Do you like this answer" on the post that helps you.
Niradhip ChakrabortyPosted Aug 3, 2009, 10:17 AM
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.
lindaPosted Aug 3, 2009, 9:21 AM
Niradhip ChakrabortyPosted Aug 3, 2009, 1:16 AM
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: