连接字符串整理
Windows身份验证:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<connectionStrings>
<add name="DataBase" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ProCMS;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<add name="DataBase" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ProCMS;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
SA验证:
</connectionStrings>
<add name="YYSYD" connectionString="Server=127.0.0.1;Database=ProCMS;uid=sa;pwd=;"/>
</connectionStrings>
<add name="YYSYD" connectionString="Server=127.0.0.1;Database=ProCMS;uid=sa;pwd=;"/>
</connectionStrings>
直接将数据库放在App_Data文件夹下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<connectionStrings>
<add name="DataBase" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProCMS.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<add name="DataBase" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProCMS.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
连接代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public SQLHelper()
{
string myProviderName = ConfigurationManager.ConnectionStrings["DataBase"].ProviderName;
string myConnectionString = ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString;
}
{
string myProviderName = ConfigurationManager.ConnectionStrings["DataBase"].ProviderName;
string myConnectionString = ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString;
}
将连接字符串放在appSettings中:
<appSettings>
<add key="ProCMS" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProCMS.mdf;Integrated Security=True;User Instance=True"/>
</appSettings>
<add key="ProCMS" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProCMS.mdf;Integrated Security=True;User Instance=True"/>
</appSettings>
连接代码:
public string ConnectionString = ConfigurationManager.AppSettings["ProCMS"].ToString();