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

    Web.config

    How to put connection string in web.config for sql?????????
  • #586081
    put this code in web.config file

    <connectionStrings>

    <add name="ConStr" connectionString="data source=servername;database=databaseName;uid=sa;password=123;Min Pool Size=2;Max Pool Size=60;Connect Timeout=15000;Pooling=true;" providerName="System.Data.SqlClient"/>
    </connectionStrings>



    hope this will help you

  • #586083
    Web.Config

    Ex:
    <add key="ConnectionString" value="Server=192.168.1.11; USER ID=eshopaid; PASSWORD=eshopaid; initial catalog=Trade;"/>

    server-->System IP address
    Trade --> Database Name

  • #586086
    Hi,

    Try this

    We have to set connection string in two ways in web.config file,

    Within <appSettings> tag,
    <appSettings>
    <add key="conLocal" value="Initial Catalog=DatabaseName;Data Source=ServerName;Integrated Security=True" />
    </appSettings>

    Within <connectionString> tag,
    <connectionStrings>
    <add name="conLocal" connectionString="Initial Catalog=DatabaseName;Data Source=ServerName;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Thanks and Regards,
    SAKTHI GOPINATH S
    http://www.mstechs.blogspot.com

  • #586087
    use this code in web.config

    <configuration>
    <connectionStrings>

    //Trusted Connection
    <add name="ConnectionString" connectionString="Data Source=myserver;Initial Catalog=database;Integrated Security=True"
    providerName="System.Data.SqlClient" />

    //Standard Security alternative syntax
    <add name="ConnectionString" connectionString="Data Source=myserver;Initial Catalog=database;User ID=uname;Password=Pass"
    providerName="System.Data.SqlClient" />
    </connectionStrings>
    </configuration>

    Aman Gandhi

  • #586102
    hi friend,

    you can follow this example :

    1st method :

    <appSettings>

    <add key="con" value ="Data Source=XYZ-PC; Initial Catalog=dbstudent; User id=sa;"/>

    </appSettings>

    or

    2nd method


    <connectionStrings>

    <add name="con" providerName="System.Data.SqlClient" connectionString = "server=XYZ-PC; database=dbstudent; uid=sa" />


    </connectionStrings>

  • #586113


    <connectionStrings>

    <add name="ConStr" connectionString="data source=servername;database=databaseName;uid=sa;password=123;Min Pool Size=2;Max Pool Size=60;Connect Timeout=15000;Pooling=true;" providerName="System.Data.SqlClient"/>
    </connectionStrings>


    All is well.
    Thanks,
    Dharma
    Editor,Mentor,MVM
    Try and fail but don't fail and try

  • #586126
    Connection String can be declared in appSettings section or connectionStrings section of Web.Config.

    If you are declaring connection string in appSettings, then use the following code:

    Web.Config
    ----------


    <appSettings>
    <add key="appcon" value="server=.;integrated security=true;database=DotNetSpider"/>
    </appSettings>


    C# Code Behind
    --------------


    string ConStrinApp = System.Configuration.ConfigurationManager.AppSettings["appcon"].ToString();
    Response.Write("Connection String in App Config: " + ConStrinApp);


    If you are declaring connection string in connectionStrings, then use the following code:

    Web.Config
    ----------


    <connectionStrings>
    <add name="webcon" connectionString="server=.;integrated security=true;database=DotNetSpider"/>
    </connectionStrings>


    C# Code Behind
    --------------


    string ConStrinWeb = System.Configuration.ConfigurationManager.ConnectionStrings["webcon"].ToString();
    Response.Write("Connection String in Web Config: " + ConStrinWeb);


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

  • #586134
    Try below code sample



    1 <?xml version="1.0" encoding="utf-8" ?>

    2 <configuration>

    3

    4 <system.web>

    5 <compilation defaultLanguage="c#" debug="true" />

    6 </system.web>

    7

    8 <appSettings>

    9 <add key="ConnectionInfo" value="server=(local);database=Northwind;Integrated Security=SSPI" />

    10 </appSettings>

    11

    12 </configuration>

  • #586138
    hi try this below coding


    </configSections>
    <appSettings>
    <add key="ConnectionString" value="Data Source=SERVER\S;Initial Catalog=DbName;User ID=sa;Password=pwd"/>
    </appSettings>
    <connectionStrings/>

    public SqlConnection con;



    then add from_load()

    {
    con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    con.Open();



    Thanks and Regards


  • 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.