用于查看链接的Microsoft Excel工作表的连接已丢失 [英] The connection for viewing your linked Microsoft Excel worksheet was lost

查看:2151
本文介绍了用于查看链接的Microsoft Excel工作表的连接已丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,



我收到错误从Excel获取数据时查看链接的Microsoft Excel工作表的连接丢失文件。



工作流程

我有一张名为 New_All.xlsx的Excel表格 始终打开,并且每隔2分钟更新该excel文件中的值。在下面的代码中,我每隔2分钟就会导入系统中的所有值。



一旦我运行它,同时测试2-5分钟,代码工作正常如果我进入实时环境,我得到以下错误并且它停止工作:



发生'System.Data.OldEb.OleDBException'类型的异常在System.Data.Dll中但未在用户代码中处理。



添加信息:查看链接的Microsoft Excel工作表的连接是丢失了。




因为我被严重困扰,任何帮助都将受到赞赏。



请找到我的页面的以下代码:





Hello Guys,

I am getting an error The connection for viewing your linked Microsoft Excel worksheet was lost while fetching data from Excel file.

Workflow
I am having an Excel Sheet called New_All.xlsx which is always open and the values in that excel file are be updated after every 2 minutes. As in my below code, I import all the values in my system after every 2 min.

Code works fine once I ran it while testing for 2-5 min but If I put into live environment, I got the below error and it stopped working:

An exception of type 'System.Data.OldEb.OleDBException' occurred in System.Data.Dll but was not handled in User code.

Addition Information:The connection for viewing your linked Microsoft Excel worksheet was lost.


As I am stuck on this badly, any help will be appreciated.

Please find the below code of my page:


string excelfilepath = "E:\\MainExcel\\Personal\\New_All.xlsx";
      public static string path = @"E:\\MainExcel\\Personal\\New_All.xlsx";
      public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              importdatafromexcel(excelfilepath);
          }
      }

      public void importdatafromexcel(string excelfilepath)
      {
          //Connection for SQL
          Connection con = new Connection();

          //create our connection strings
          string sexcelconnectionstring = connStr;
          OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
          oledbconn.Open();
          DataTable dtsheet = new DataTable();
          //All sheets' names in excel file
          dtsheet = oledbconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
          //declare variables - edit these based on your particular situation

          if (dtsheet == null)
          {
              return;
          }

          //Creat an array to store the name of Sheets.
          String[] excelSheets = new String[dtsheet.Rows.Count];
          int i = 0;

          // Add the sheet name to the string array.
          foreach (DataRow row in dtsheet.Rows)
          {
              excelSheets[i] = row["TABLE_NAME"].ToString().Trim(new Char[] { '\'' });
              i++;
          }

          for (int j = 0; j < excelSheets.Length; j++)
          {
              // make sure your sheet name is correct, here sheet name is sheet1, so you can change your sheet name if have different
              string myexceldataquery = "Select * from [" + excelSheets[j] + "]";

              OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
              DataTable dt = new DataTable();
              OleDbDataAdapter da = new OleDbDataAdapter(oledbcmd);
               da.Fill(dt);

              int ids = 0;
              string s_symbol = "", s_expiry_date = "", s_min_lot_qty = "", s_best_buy_qty = "", s_best_buy_rate = "", s_best_sell_rate = "", s_best_sell_qty = "", s_last_traded_price = "", s_last_trade_qty = "", s_percentage_change = "", s_ATP = "", s_low_price = "", s_high_price = "", s_open_price = "", s_time_date;
              DateTime timedate;
              timedate = DateTime.Now;
              int row;
              for (row = 0; row < dt.Rows.Count; row++)
              {

                  s_symbol = dt.Rows[row][0].ToString();
                  s_expiry_date = dt.Rows[row][1].ToString();
              }
        }
     }

推荐答案

Excel 不支持 [ ^ ]多用户并发 - 这并不奇怪,它不是数据库:)
Excel doesn't support[^] multi-user concurrency - which isn't surprising, it's not a Database :)


这篇关于用于查看链接的Microsoft Excel工作表的连接已丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆