app.config或web.config存放数据库连接字符串的两种方式

<connectionStrings>
        <add name="connstr" connectionString="Data Source=192.168.253.11;Initial Catalog=STRFID;User ID=sa;Password=unionsun;" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    <appSettings>
        <add key="connstr" value="Data Source=192.168.253.11;Initial Catalog=STRFID;User ID=sa;Password=unionsun;" />
    </appSettings>

 

using System.Configuration;

public static string connectionString = ConfigurationManager.AppSettings["connstr"].ToString();
protected static string connectionString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString.ToString();

你可能感兴趣的:(config)