예제 #1
0
 private void buttonTestConnection_Click(object sender, EventArgs e)
 {
     if (textBoxServer.Text == "" || textBoxDataBase.Text == "")
     {
         MessageBox.Show("Server与DataBase不能为空!");
     }
     else
     {
         try
         {
             using (SqlConnection sqlConnection = new SqlConnection
                                                      (System.Text.RegularExpressions.Regex.Unescape
                                                          (connection.CreateConnectionString
                                                              (textBoxServer.Text, textBoxDataBase.Text, textBoxuid.Text, textBoxpwd.Text))))
             {
                 sqlConnection.Open();
                 MessageBox.Show("连接成功!");
             }
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message);
         }
     }
 }