取消通过单击取消按钮存储过程执行

时间:2018-08-08 05:39:35

标签: execution

我正在学习SQL Server DBA的知识。 为了测试SQL HA和DR,我刚刚创建了一个C#桌面应用程序,以在SQL数据库中插入100万条记录。

但不确定如何使用“取消”按钮(button2)取消存储过程的执行。

这是下面的代码和屏幕截图

能否请您添加/建议一个代码,如果我单击一个新创建的按钮(button2),它将停止存储过程的执行,以便我可以测试SQL Ha和DR。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=xxxxx;Initial Catalog=APP_TEST_DB;Integrated Security=True");
        public Form1()
        {InitializeComponent();

                    }   private void Form1_Load(object sender, EventArgs e)
        {`enter code here`



            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT count(*) FROM customers;";
            Int32 count = (Int32)cmd.ExecuteScalar();
            textBox1.Text = count.ToString();


            con.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;

            cmd.CommandText = "Exec TESTProc ";
            cmd.ExecuteNonQuery();
            con.Close();

            MessageBox.Show("Record inserted successfully");



                con.Open();
                cmd.CommandText = "SELECT count(*) FROM customers;";
                Int32 count = (Int32)cmd.ExecuteScalar();
                textBox1.Text = count.ToString();


                con.Close();





        }

        private void button2_Click(object sender, EventArgs e)
        {
         // May i know what code should i put here please
        }
        }
        }

0 个答案:

没有答案