You must Sign In to post a response.
  • Category: .NET

    Application config file in

    How to use Application configuration file in the Application?
  • #648383
    this is application configuration file in which connection string is present:

    <?xml version="1.0" encoding="utf-8" ?>
    <add key="connectionString" value="server = XYZ\SQLEXPRESS; Integrated Security = SSPI; Database = ABC"/>

    in below code app.config file is used to connect the databse.

    connectionString = ConfigurationManager.AppSettings["connectionString"];
    sqlConnection = new SqlConnection(connectionString);


    Catch(Exception ex)


    With Regards

  • #648418
    You can store the Connection String in App.Config file.

    Please follow these steps:

    1) Right Click on the Windows Application -> Add -> New Item... -> Select Application Configuration File -> Ok

    2) In the newly add App.Config file, add the following entry within configuration element:

    <add key="sqlcon" value="server=.;integrated security=true;database=databasename;"/>

    3) In the form you can use the following code to read the Connection String:

    string ConnectionString = ConfigurationSettings.AppSettings["sqlcon"].ToString();

    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #648542
    Configuration file is used to add setting related to whole application like:
    For adding connection string you can use:

    <add key="MyConnectionString" value="server = dell;integrated security=true;database=Employee;"/>

    For disabling viewstate we can use:

    <pages enableviewstate="false"/>

    Microsoft Certified Technology Specialist
    MY Blog..

  • #648593
    connectionStrings in web.config file like this:

    <add name="dbconnection" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MyDB" providerName="System.Data.SqlClient"/>
    </connectionStrings >

    Please check below code:

    using System;
    using System.Data.SqlClient;
    using System.Configuration;
    public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    //Get connection from web.config file
    string conn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
    SqlConnection con = new SqlConnection(conn);

    Software Engg.

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.