无法将Excel文件上传到ASP.NET网站

时间:2019-05-04 09:56:48

标签: asp.net iis server database-connection website-hosting

将Excel文件上传到网站时出现此错误。服务器托管支持还启用了IIS中的32位高级设置,但我仍然收到此错误

  

C:\ Inetpub \ vhosts \ libertyenterprises.pk \ httpdocs \ Document \ Temp \ Inventory   上传样本04112019_151139.xlsx

     

C:\ Inetpub \ vhosts \ libertyenterprises.pk \ httpdocs \ Document \ Temp \ Inventory   上传样本04112019_151139.xlsx

     

System.InvalidOperationException:“ Microsoft.ace.OLEDB.12.0”   提供程序未在本地计算机上注册。

     

at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr,DataSourceWrapper&datasrcWrapper)
  在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString构造,OleDbConnection连接)上
  在System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection owningObject)
  在System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey池密钥,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection拥有的连接,DbConnectionOptions用户选项)
  在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionOptions userOptions)
  在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions userOptions)处   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection   externalConnection,DbConnectionFactory connectionFactory,   重试TaskCompletionSource`1,DbConnectionOptions userOptions)位于   System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection   externalConnection,DbConnectionFactory connectionFactory)位于   System.Data.OleDb.OleDbConnection.Open()位于   中的BusinessLayer.Common.GetExcelSheetNames(String excelFile)   e:\ Projects \ Other \ InventoryManagement \ BusinessLayer \ Common.cs:line 755

使用以下代码

  

公共对象ImportExcel()           {               尝试               {                   ProductClass objProduct = new ProductClass();                   DbManager管理器=新的DbManager();                   DataTable dtProduct = objProduct.ImportFromExcel(HttpContext.Current.Session [“ TempFilePath”]。ToString());                   字符串类别= string.Empty;                   字符串Brand = string.Empty;                   字符串模型= string.Empty;                   字符串Branch = string.Empty;                   字符串数量=字符串。空;                   字符串ProductDescription = string.Empty;                   字符串ClaimNumbers = string.Empty;

            if (dtProduct != null && dtProduct.Rows.Count > 0)
            {

                for (int i = 0; i < dtProduct.Rows.Count; i++)
                {
                    Category = dtProduct.Rows[i]["Category"].ToString().Trim();
                    Brand = dtProduct.Rows[i]["Brand"].ToString().Trim();
                    Model = dtProduct.Rows[i]["Model"].ToString().Trim();
                    Branch = dtProduct.Rows[i]["Branch"].ToString().Trim();
                    Quantity = dtProduct.Rows[i]["Quantity"].ToString().Trim();
                    ProductDescription = dtProduct.Rows[i]["Item Description"].ToString().Trim();
                    InventoryClass obj = new InventoryClass();
                    int result = obj.ImportStock(Category, Brand, Model, ProductDescription, Branch, Quantity);

                }

                return new { Result = "OK", Message = "Imported Successfully", ClaimNumbers = ClaimNumbers.TrimEnd(',') };

            }
        }
        catch (Exception ex)
        {
            return new { Result = "error", Message = "Fail to import" };
        }
        return null;
    }

} }

0 个答案:

没有答案