日期:2014-05-17  浏览次数:20443 次

导入EXCEL数据到sql2005中 出现“正在中止线程。”错误
C# code
string strPath = UploadFile(FileUpload1, Server.MapPath("/uploads/excel/"));
                    string sConnectionString =
                        "Provider=Microsoft.ACE.OLEDB.12.0;" +
                    "Data Source=" + Server.MapPath("/uploads/excel/") + strPath + ";" +
                    "Extended Properties=\"Excel 8.0;HDR=Yes;\"";
                    //Utility.Utility.Go_Error(Server.MapPath(FileUpload1.PostedFile.FileName.ToString()));
                    //string sConnectionString = @"Provider=MICROSOFT.JET.OLEDB.4.0;Extended Properties='Excel 8.0;IMEX=1';DATA SOURCE=" + FileUpload1.PostedFile.FileName.ToString();
                    //建立EXCEL的连接
                    OleDbConnection objConn = new OleDbConnection(sConnectionString);
                    // Utility.Utility.Go_Error(strPath);
                    objConn.Open();

                    OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + FileUpload1.FileName.Substring(0, FileUpload1.FileName.IndexOf('.')) + "$]", objConn);
                    OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
                    objAdapter1.SelectCommand = objCmdSelect;

                    DataSet objDataset1 = new DataSet();

                    objAdapter1.Fill(objDataset1, "XLData");

                    DataTable dt = objDataset1.Tables[0];

用的是这种方法导入EXCEL

但是一旦数据量超大就会报错

报“正在中止线程。”;

其实也才2W多条就不行了。

请问怎么解决呢。

------解决方案--------------------
增加应用程序的 Web.config 文件的 元素中 memoryLimit 属性的值。例如:
XML code
<configuration>
       <system.web>
              <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
          <processModel memoryLimit="80"/>
       </system.web>
</configuration>