//Integrated Security=true是Windows身份验证,默认false.
//COM125计算机名,SQLEXPRESS数据库实例名,本机可以写成.\\SQLEXPRESS<pre name="code" class="csharp"><span style="font-family: Arial, Helvetica, sans-serif;">string strCon = "Data Source =COM125\\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=true";</span>
string strCon2 = "Server=COM125\\SQLEXPRESS;Database=TestDB;User ID=tang;Password=123123;";
SqlConnection dataConnection = new SqlConnection();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = ".\\SQLExpress"; //COM125\\SQLEXPRESS(计算机名\\数据库实例名)
builder.InitialCatalog = "TestDB";
builder.IntegratedSecurity = true; //以windows身份验证连接数据库
dataConnection.ConnectionString = builder.ConnectionString;