Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123
使用Windows驗證
Data Source=.;Initial Catalog=Northwind;Integrated Security=True
Data Source資料來源
Initial Catalog要連結的資料庫
User ID使用者名稱Password密碼
Integrated Security=True(使用Windows驗證登入)
web.config
Sql驗證
<connectionStrings>
<add name="DBConnectionString" connectionString="Data Source=.;Initial Catalog=abc;User ID=sa;Password=abc" providerName="System.Data.SqlClient" />
</connectionStrings>
windows驗證
<add name="DBConnectionString" connectionString="data source=.;initial catalog=ShuLong;integrated security=true;"/>
.cs裡
using System.Configuration;//抓Web.config用
string Conn = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;