答案 0 :(得分:0)
您只需在Web Config文件中设置连接字符串,然后根据您的要求引用它即可。请参见下文
Web配置:
<connectionStrings>
<add name="SQLDBConnectionString" connectionString="Data Source=<SERVER NAME>;Initial Catalog=<DATABASE NAME>;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
然后获取连接的引用:
public string SQLServerDBConnstring()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["SQLDBConnectionString"].ToString();
}