// windows验证方式
string connectionStringTest = @"Data Source=ADMINISTRATOR\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=SSPI; ";
//建立信任连接(具体含义与同其他方式的区别还需学习)
string connectionStringTest = @"server=ADMINISTRATOR\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True";
//网站连接数据库的标准方式
string connectionStringTest = @"server=ADMINISTRATOR\SQLEXPRESS;database=TestDB;user id=testuser;password=123456";
//应用程序连接数据库的标准方式
string connectionStringTest = @"Data Source = ADMINISTRATOR\SQLEXPRESS; Initial Catalog = TestDB; User Id = testuser; Password = 123456;";
SqlConnection conn = new SqlConnection(connectionStringTest);
try
{
conn.Open(); MessageBox.Show("数据库链接成功!","提示");
}
catch (Exception e)
{
string message = e.Message;
}
finally
{
conn.Close();
conn.Dispose();
}