一、Windows身份验证方式
SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source = .\SQL2005 ; Integrated Security = true ; Initial Catalog = Study";
二、SQL Server 身份验证方式
SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source = .\SQL2005 ; User ID = sa ; Password = 123 ; Initial Catalog = Study";
注:示例中的服务器名称:SQL2005,用户名:sa,密码:123,数据库名:Study。