October 9, 2015 07:00 by Dan
This post explains How to Write Or Read Connection String From ASP.NET Web Config for DB driven Applications. We can either use connectionStrings section or AppSettings and can Write Programmatically At Run Time as well. Sql Server information is usually written inside <configuration>
Initial Catalog=Northwind;User ID=amit;Password=password"
Where Data Source is db Server Address, Initial Catalog is DataBase Name. To use Windows Authentication instead of Sql Server Authentication write
Initial Catalog=Northwind;Integrated Security=True"
For database attached in App_Data Folder we can write
Integrated Security=True;User Instance=True"
USING APPSETTINGS We can also write data in Key Value pairs.
READING WEB.CONFIG FILE PROGRAMMATICALLY We can write code as mentioned below.
string strConn = ConfigurationManager.ConnectionStrings["MyCon"].ConnectionString;
string strConn = ConfigurationManager.AppSettings["con"].ToString();
Dim strConn As String = ConfigurationManager.ConnectionStrings("MyCon").ConnectionString
Dim strConn As String = ConfigurationManager.AppSettings("con").ToString()
Best ASP.NET 4.6 Hosting Recommendation
ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.