Udostępnij za pośrednictwem


Database Connection String

Database Connection String

資料庫連線字串


System.Data.SqlClient

 "Persist Security Info=False;User ID=*****;Password=*****;Initial Catalog=AdventureWorks;Server=MySqlServer"
"Data Source=MSSQL1;Initial Catalog=AdventureWorks;Integrated Security=true;"
"Persist Security Info=False;Integrated Security=true; Initial Catalog=AdventureWorks;Server=MSSQL1"
"Persist Security Info=False;Integrated Security=SSPI; database=AdventureWorks;server=(local)"
"Persist Security Info=False;Trusted_Connection=True; database=AdventureWorks;server=(local)"
"Data Source=MySqlServer\MSSQL1;"

 

註解:

Windows驗證可以用Integrated Security=true或Integrated Security=SSPI(建議)或Trusted_Connection=True

SQL驗證可以用User ID=AppUser1或UID=AppUser1 與 Password=AppUser1Password 或 PWD=AppUser1Password

指定預設連接資料庫可以用database=AdventureWorks或Initial Catalog=AdventureWorks

SQL Server主機有更多寫法,常用的是 Data Source=MSSQL1或 Server=MSSQL1

 

Reference:
SqlConnection.ConnectionString Property
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx
Connection String Syntax
/en-us/dotnet/framework/data/adonet/connection-string-syntax