- asp.net 项目配置文件:Web.config;winfrom项目配置文件:App.config
写入下面代码
根据需要自行选择本地或者sa账户
<configuration><!--数据库连接-本地--><!--<connectionStrings><add name&#61;"connectionString"connectionString&#61;"server&#61;.;Initial Catalog&#61;ss;Integrated Security&#61;True"providerName&#61;"System.Data.SqlClient"/></connectionStrings>--><!--数据库连接-sa--><connectionStrings><!--数据库 jjq_connStr_SQL Server--><add name&#61;"ConnectionString"connectionString&#61;"Data Source&#61;10.xx.xx.xx;Initial Catalog&#61;D_xx;User ID&#61;sa;Password&#61;sa;"providerName&#61;"System.Data.SqlClient" /></connectionStrings></configuration>
2.cs代码中&#xff1a;
using System.Configuration;private static string constr &#61; ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
数据库连接的其他方式