May 27, 2010

Connection String - Adding connection string to Web.config file and accessin it (ASP.NET, C#)

Web.config File:

We can add conncetion string in web.config file for security reasons, in the following way:

<configuration>

<appSettings>

<add key="ConnectString" value="Server=servername;Database=databasename;uid=yourUserId;pwd=yourPassword"/>

Default.aspx.cs page:

Getting Connection String from web.config in c# program )(For example, Default.aspx.cs page_load event)

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString Name"].ConnectionString);

No comments:

Post a Comment