示例#1
0
        public static void RunIfDbExists(RunningIfDbExist myMethod, string dbName)
        {
            SqlCommand myCommand = new SqlCommand(string.Format(@"USE {0};", dbName),
                                                      new SqlConnection(Settings.Default.cnnStr));
            try
            {
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                myCommand.Connection.Close();

                myMethod();
            }
            catch (SqlException ex)
            {
                if (myCommand.Connection.State != ConnectionState.Closed)
                {
                    myCommand.Connection.Dispose();
                }

                MessageBox.Show(ex.Message, "Connection Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
示例#2
0
        public static void RunIfDbExists(RunningIfDbExist myMethod, string dbName)
        {
            SqlCommand myCommand = new SqlCommand(string.Format(@"USE {0};", dbName),
                                                  new SqlConnection(Settings.Default.cnnStr));

            try
            {
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                myCommand.Connection.Close();

                myMethod();
            }
            catch (SqlException ex)
            {
                if (myCommand.Connection.State != ConnectionState.Closed)
                {
                    myCommand.Connection.Dispose();
                }

                MessageBox.Show(ex.Message, "Connection Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }