• Related Post

    Friday, January 23, 2015

    ASP.Net Code Using C# - Connection String , SQL Connection String

    connection string in asp.net with C# Code

    Connection String in aspx_page

    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"    (from web.config file)

    Connection String in aspx.cs_page


    SqlConnection cnn = new SqlConnection();
    cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    Connection String in Web.config_page


    <configuration>
          <appSettings/>
          <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
       providerName="System.Data.SqlClient" />
     </connectionStrings>

    Or

    <connectionStrings>
      <add name="ConnectionString" connectionString="Server=omgoelmdfromusa.db.2263994.hostedresource.com; Database=omgoelmdfromusa;User ID=omgoelmdfromusa;Password=Bondo@321; Trusted_Connection=False"
       providerName="System.Data.SqlClient" />

     </connectionStrings>

    No comments:

    Post a Comment