Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可能是繁重的查询导致asp.net中停止运行后续代码?_C#_Sql_Asp.net - Fatal编程技术网

C# 是否可能是繁重的查询导致asp.net中停止运行后续代码?

C# 是否可能是繁重的查询导致asp.net中停止运行后续代码?,c#,sql,asp.net,C#,Sql,Asp.net,我在我的Asp.net项目中有一个查询,它创建了两个表,然后在其中插入日期,当有新数据时,所以没有问题,这是我的查询: protected void btnLottryInformationSave_Click(object sender, EventArgs e) { try { int rowCount; var finalTempTableName = FindTableName();

我在我的
Asp.net
项目中有一个查询,它创建了两个表,然后在其中插入日期,当有新数据时,所以没有问题,这是我的查询:

    protected void btnLottryInformationSave_Click(object sender, EventArgs e)
    {
        try
        {
            int rowCount;
            var finalTempTableName = FindTableName();

            var selecterServicesList = cblServices.Items.Cast<ListItem>().Where(x => x.Selected).ToList();
            var selectedServices = selecterServicesList.Aggregate(string.Empty, (current, service) => current + ("'" + service.Value + "',")).TrimEnd(',');

            var tempTableName = "Temp_" + finalTempTableName;

            var drawQuery = " if (OBJECT_ID('Temp.dbo." + tempTableName + "') is not null) \ndrop table Temp.dbo." + tempTableName + ";\n";
            drawQuery += " create table Temp.dbo." + tempTableName + "(Number char(11) primary key,RepCount int);\n";
            drawQuery += " if (OBJECT_ID('Temp.dbo." + finalTempTableName + "') is not null) \ndrop table Temp.dbo." + finalTempTableName + ";\n";
            drawQuery += " create table Temp.dbo." + finalTempTableName + "(Id int identity(1,1) primary key,Number char(11));\n";

            drawQuery += " select org.orig \n" +
                         "   into #MoOrig \n" +
                         "    from VSReceiveSend.dbo.OrigPrices org  \n" +
                         "          INNER JOIN VSReceiveSend.dbo.Services     s on (s.Orig   = org.Orig) \n" +
                         " where s.Code in (" + selectedServices + ") and org.MTPrice <> 0  \n ";

            if (drpLotteryType.SelectedValue == "1" || drpLotteryType.SelectedValue == "2")
            {
                drawQuery += " INSERT INTO Temp.dbo." + tempTableName + " (Number,RepCount)\n" +
                             " select number," + (drpLotteryType.SelectedValue == "1" ? "1" : "sum(c) ") +
                             " from (\n" +
                             "     SELECT Number,COUNT(*) c \n" +
                             "     FROM  VSReceiveSend.dbo.ReceivedSMS with(nolock)\n" +
                             "            INNER JOIN VSReceiveSend.dbo.#MoOrig org ON (org.Orig = ReceivedSMS.Orig) \n " +
                             "     WHERE  Date BETWEEN '" + dtpStartDate.Text + "' AND '" + dtpEndDate.Text + "' \n" +
                             "     GROUP BY Number\n" +
                             "     union all \n " +
                             "     SELECT Number,COUNT(*) c \n" +
                             "     FROM  VSReceiveSend.dbo.SentSMS with(nolock) \n" +
                             "            INNER JOIN VSReceiveSend.dbo.OrigPrices org ON (org.Orig = SentSMS.Orig AND org.MTPrice <> 0 ) \n " +
                             "     WHERE  SentDate BETWEEN '" + dtpStartDate.Text + "' AND '" + dtpEndDate.Text + "' AND SentSMS.ServiceCode in (" + selectedServices + ") \n" +
                             "     GROUP BY Number \n" +
                             " ) DerivedTable \n" +
                             " group by number \n" +
                             ((drpLotteryType.SelectedValue == "2" && txtMinAnswerCount.Text != "") ? "HAVING sum(c) >= " + txtMinAnswerCount.Text : "") + ";\n";
            }
            else if (drpLotteryType.SelectedValue == "3")
            {
                var pointCount = int.Parse(txtMinCustomerPoint.Text);

                drawQuery += " INSERT INTO Temp.dbo." + tempTableName + " ( Number,RepCount)\n" +
                             "                                            SELECT Number,SUM(Point) / " + txtDivPoints.Text + " RepCount " +
                             "                                    FROM VsReceiveSend.dbo.SubscriberMatchHistory with(nolock) \n" +
                             "                                where ServiceCode in (" + selectedServices + ") and SUBSTRING(DateTime,1,10)  BETWEEN '" + dtpStartDate.Text + "' AND '" + dtpEndDate.Text + "' \n" +
                             "                                GROUP BY Number\n" +
                             " HAVING SUM(Point) >= " + pointCount + ";\n";
            }

            drawQuery += " with DrawInfo (Number,RepCount) as \n" +
                         "(   select Number,1 \n" +
                         "    from temp.dbo." + tempTableName + "\n" +
                         "       union all \n" +
                         "    select DrawInfo.Number,DrawInfo.RepCount + 1 \n" +
                         "        from Temp.dbo." + tempTableName + "\n" +
                         "    inner join DrawInfo on (DrawInfo.Number = Temp.dbo." + tempTableName + ".Number and DrawInfo.RepCount + 1 <= " + tempTableName + ".RepCount) \n" +
                         ")\n" +
                         " Insert into Temp.dbo." + finalTempTableName + "(Number) \n" +
                         " select DrawInfo.Number \n" +
                         " from DrawInfo";
            if (!checkBoxOrderInformation.Checked)
                drawQuery += " ORDER BY ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)) \n";
            else
                drawQuery += " ORDER BY Number \n";

            drawQuery += " option (maxrecursion 0);\n " +
                         " select count(*) from Temp.dbo." + finalTempTableName;


            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["VasunReportConnectionString"].ConnectionString))
            {
                var command = new SqlCommand(drawQuery, connection) { CommandTimeout = 999999999 };
                connection.Open();
                drawFieldSet.Visible = true;
                rowCount = (int)command.ExecuteScalar();

                txtNumberOfRow.Text = rowCount.ToString(CultureInfo.InvariantCulture);
            }

            using (var dbs = new ReceiveSendEntitiesV5())
            {
                var matchDrawHistories = new MatchDrawHistory()
                {
                    DrawStartDate = dtpStartDate.Text,
                    DrawEndDate = dtpEndDate.Text,
                    DrawTime = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(),
                    RowNumber = rowCount,
                    ServiceCode = cblServices.SelectedValue,
                    TableName = finalTempTableName
                };
                dbs.MatchDrawHistories.Add(matchDrawHistories);
                dbs.SaveChanges();
            }

        }
        catch (Exception exp)
        {
            ErrorLabel.Text = "Exception :" + exp.Message;
        }
    }

这是怎么可能的!!!有什么问题?

您的字符串操作很奇怪。改为使用@prefix、
string.Format
StringBuilder
。似乎您遇到了超时问题。是否存在任何异常?请尝试在SQL Management Studio中运行生成的命令。你试过调试你的c#代码吗?我的代码工作正常,当我从一些记录中抽取大约800.000的彩票时,我的代码完全执行,但当记录量大约为25000000时,我的代码执行到:txtNumberOfRow.Text=rowCount.ToString(CultureInfo.InvariantCulture),它没有给我执行权@我做了,它工作正常!
 using (var dbs = new ReceiveSendEntitiesV5())
        {
            var matchDrawHistories = new MatchDrawHistory()
            {
                DrawStartDate = dtpStartDate.Text,
                DrawEndDate = dtpEndDate.Text,
                DrawTime = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(),
                RowNumber = rowCount,
                ServiceCode = cblServices.SelectedValue,
                TableName = finalTempTableName
            };
            dbs.MatchDrawHistories.Add(matchDrawHistories);
            dbs.SaveChanges();
        }