1. Make sure you have a connection string in your Web.config file. A connection string looks something like this.
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=(local);
Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
2. Now in the Default.aspx.cs file type in the following in the top of the file, where all the using statements are to use the System.Web.Configuration namespace
using System.Web.Configuration;Obviously you can use it in any .cs file, the Default.aspx.cs is just an example.
3. In the Page_Load method type in the following line
string connectString = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].To display the connection string on your browser, type the following line
ConnectionString;
Response.Write(connectString);
No comments:
Post a Comment