常用的数据库连接设置:
web/app.config配置
windows身份验证
<connectionStrings>
<add name="ConnString" connectionString="Data Source=.;Initial Catalog=HotelDataBase;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
sql server身份验证
<configuration>
<connectionStrings>
<add name="ConnString" connectionString="server = .;uid = sa;pwd =123456;database = HotelDataBase"
providerName="System.Data.SqlClient"/>
</connectionStrings>
全局性的使用数据库,只需要用以下连接:
connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
【注意】添加的连接名字和连接字符串名字二者要一致!