在处理大量数据时会出现致命错误

时间:2017-05-10 14:45:52

标签: mysql exception

下面我附上了我的代码。在我的代码中,它停在了一行:

cmdUpdate.executenonquery(); 

并在几秒钟后生成异常并执行catch块。在catch块中它表示

  

致命错误

我不知道为什么会出现这种错误。 一个主要的重要事项是首先我在LIMIT命令中指定的查询中没有任何cmdPayment条件执行此代码。然后它不会生成任何异常。 但是当我从查询中删除LIMIT条件时,它会生成异常。

此查询将从表中选择大约20的数据。

int freeMonths=0;
        string subscriptionTxnId = null;
        string paymentType=null;
        string subscriptionDate = null;
        string userid = null;
        string date = "2014-02-01 00:00:00";

        using (MySqlConnection connPayment = new MySqlConnection(connString))
        {
            connPayment.Open();

            freeMonths = 0;

            MySqlCommand cmdPayment = new MySqlCommand("SELECT userid,subscr_txn_id,DATE_FORMAT(subscr_date,'%Y-%m-%d %k:%i:%s'),payment_type from payment limit 10000",connPayment);
            MySqlDataReader readerPayment;

            readerPayment = cmdPayment.ExecuteReader();




            while (readerPayment.Read())
            {

                try
                {
                    freeMonths = 0;

                    if (readerPayment.GetValue(0) != DBNull.Value && readerPayment.GetValue(1) != DBNull.Value && readerPayment.GetValue(2) != DBNull.Value && readerPayment.GetValue(3) != DBNull.Value)
                    {

                        userid = readerPayment.GetString(0);
                        subscriptionTxnId = readerPayment.GetString(1);
                        subscriptionDate = readerPayment.GetString(2);
                        paymentType = readerPayment.GetString(3);


                        using (MySqlConnection connPaymentDetails = new MySqlConnection(connString))
                        {
                            connPaymentDetails.Open();
                            MySqlCommand cmdPaymentDetails = new MySqlCommand("select free_months from payment_details where userid = '" + userid + "' AND subscr_txn_id ='" + subscriptionTxnId + "' AND payment_date = '" + subscriptionDate + "' ", connPaymentDetails);

                            MySqlDataReader readerPaymentDetails = cmdPaymentDetails.ExecuteReader();

                            if (readerPaymentDetails.HasRows)
                            {
                                readerPaymentDetails.Read();

                                freeMonths = readerPaymentDetails.GetInt32(0);
                            }

                        }


                        string query = null;

                        MySqlConnection conUpdate = new MySqlConnection(connString);


                        if (paymentType == "annual" || paymentType == "Annual")
                        {
                            //MySqlCommand cmd001 = new MySqlCommand("")


                            query = "update payment set end_date = (select DATE_ADD(DATE_ADD('" + subscriptionDate + "' ,INTERVAL 1 YEAR),INTERVAL '" + freeMonths + "' MONTH)) where subscr_date = '" + subscriptionDate + "' AND userid = '" + userid + "' AND subscr_txn_id ='" + subscriptionTxnId + "' ";
                        }
                        else if (paymentType == "quarter" || paymentType == "Quarter" || paymentType == "Quarterly")
                        {
                            freeMonths += 3;
                            query = "update payment set end_date = (select DATE_ADD('" + subscriptionDate + "', INTERVAL '" + freeMonths + "' MONTH)) where subscr_date = '" + subscriptionDate + "'  AND userid = '" + userid + "' AND subscr_txn_id ='" + subscriptionTxnId + "' ";
                        }
                        else if (paymentType == "month" || paymentType == "Month" || paymentType == "Monthly")
                        {
                            freeMonths += 1;
                            query = "update payment set end_date = (select DATE_ADD('" + subscriptionDate + "', INTERVAL '" + freeMonths + "' MONTH)) where subscr_date = '" + subscriptionDate + "'  AND userid = '" + userid + "' AND subscr_txn_id ='" + subscriptionTxnId + "' ";
                        }

                        MySqlCommand cmdUpdate = new MySqlCommand(query, conUpdate);
                        conUpdate.Open();
                        cmdUpdate.ExecuteNonQuery();

                        int num = 0;
                        if (num == 0)
                        {

                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }

0 个答案:

没有答案