Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Visual studio 2013 尝试通过Microsoft.ACE.OLEDB驱动程序读取xlsx信息时出现未指定错误_Visual Studio 2013_Oledb_Xlsx - Fatal编程技术网

Visual studio 2013 尝试通过Microsoft.ACE.OLEDB驱动程序读取xlsx信息时出现未指定错误

Visual studio 2013 尝试通过Microsoft.ACE.OLEDB驱动程序读取xlsx信息时出现未指定错误,visual-studio-2013,oledb,xlsx,Visual Studio 2013,Oledb,Xlsx,我有一个应用程序已从Visual Studio 2010(运行在Windows Server 2003上)升级到Visual Studio 2013(现在运行在Windows Server 2008上)。该应用程序的一个方面允许用户将xlsx工作表上传到文件夹,并通过脚本验证其内容 我有这个方法: Private Function GetValuesFromExcel(ByVal strFileIn As String) As DataSet Dim ds As DataSet = N

我有一个应用程序已从Visual Studio 2010(运行在Windows Server 2003上)升级到Visual Studio 2013(现在运行在Windows Server 2008上)。该应用程序的一个方面允许用户将
xlsx
工作表上传到文件夹,并通过脚本验证其内容

我有这个方法:

Private Function GetValuesFromExcel(ByVal strFileIn As String) As DataSet

    Dim ds As DataSet = New DataSet
    Dim strConn As String = ""
    Try

        If strFileIn.ToLower().EndsWith(".xlsx") Then
            'This one is good for files that are saved with Excel
            strConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" + strFileIn + "'; Extended Properties=Excel 12.0 Xml;"

        Else
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + strFileIn + "'; Extended Properties=Excel 8.0;"
        End If

        Dim conn = New OleDb.OleDbConnection(strConn)

        conn.Open()
        Dim dtExcelTables As DataTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})

        Dim strExcel As String = "select * from [" + dtExcelTables.Rows(0)("TABLE_NAME").ToString() + "]"

        Dim myCommand = New OleDb.OleDbDataAdapter(strExcel, strConn)
        myCommand.TableMappings.Add("Table", "table1")
        'myCommand.Fill(ds, "table1")
        myCommand.Fill(ds)
        conn.Close()

    Catch ex As Exception
        DBUtils.WriteToLog("Error", "GetValuesFromExcel", ex.Message, Security.GetCurrentUser())
        Throw ex
    End Try

    Return ds

End Function
conn.Open()
上,它抛出一个错误。具体来说,最优秀的错误是“未指定错误”。非常有用

我们使用的是Office2007,我已经检查过以确保确实安装了32位Access数据库引擎redistributable


这到底是什么问题?

我会稍微解释一下,你不太可能得到“按这个按钮解决你的问题”的答案

您得到的错误是
E_FAIL
,一个通用的COM错误代码。通常由Microsoft软件在无法准确猜测故障的根本原因时使用。猜测一个更具体的问题风险太大,会让他们的客户陷入困境。这通常是COM的责任,它不直接支持异常,只支持错误代码。因此,丢失的一个主要特征是堆栈跟踪,这一线索可以提供有关检测到错误的特定层的大量信息

处理这些问题的唯一真正方法是通过消除过程。这在这里是可行的,代码很早就失败了。唯一可能出错的是提供错误的连接字符串、提供错误的数据或在错误的执行上下文中运行代码。勾选常见错误:

  • 错误的连接字符串语法。不是你的问题
  • 文件的路径无效。不是你的问题,产生了一个好的信息
  • 文件实际上不是Excel文件。不是你的问题,产生了一个好的信息
  • 正在尝试在64位进程中运行此操作。不是你的问题,好消息
不太常见且不容易消除的错误:

  • 程序作为服务运行,其帐户存在可访问性问题。通过使用一个小的控制台模式应用程序进行测试来消除这一点
  • 该文件是一个.xlsx文件,但它被微妙地损坏了。通过使用一组其他.xlsx文件进行测试来消除这种情况
最可能的原因是:

  • OleDb提供程序未正确安装。这也是微软代码放弃E_FAIL等一般错误的常见原因。当然,很难诊断,通过使用SysInternals的进程监视器并比较好的跟踪和坏的跟踪,您可能会有所收获。发现丢失的文件或注册表项很好。请记住,在安装Office后安装32位Access数据库引擎(可再发行)不是一个好主意,它只用于没有Office可用的机器上。你必须至少旋转一次重新安装的幸运轮

也许痛苦也是放弃这些提供者的一个很好的理由。该网站获得了相当好的评论,在服务器上的扩展性也相当好。

我支持Hans的想法,即可能放弃这些提供商,寻找替代方案

我最近经历了一个与你们面临的类似的问题。我开发了一个在我的机器上运行良好的解决方案,但在其他机器上没有,因为他们没有安装必要的驱动程序

我的情况是在客户端机器上安装Winforms应用程序,我无法控制安装了哪些外部提供商(ACE、JET等)。我们也不知道他们安装了什么版本的Office。我们要么提供一个复杂的解决方案,能够使用安装的任何驱动程序……要么寻找替代方案

我们选择了后者,并与之同行。大约30分钟后,解决方案现在可以工作,而不依赖于部署到的机器的配置

我的代码只需将Excel文件(由SSRS报告生成)中的数据读取到内存中的数据表中,以便进行一点数据比较。我们最终采用的方法显示了它的实现是多么简单

        /// <summary>
        /// Read data from MS Excel saved as an export from their SSRS reports.
        /// This method uses ExcelDataReader <link>https://github.com/ExcelDataReader/ExcelDataReader</link>
        /// to avoid dependencies on OleDb Jet or ACE drivers. Given we can't control what is installed on 
        /// client machines, we can't assume they'll have the correct drivers installed, and therefore we'll
        /// make use of ExcelDataReader. 
        /// </summary>
        /// <param name="filename">Filename to the path of the Excel (xls or xlsx) file.</param>
        /// <returns>DataTable containing the required data or null if no data is found.</returns>
        private DataTable ReadDataFromUsingExcelReader(string filename)
        {
            DataTable returnval = null;
            DataSet result = null;

            using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read))
            {
                if (filename.EndsWith("xls", StringComparison.OrdinalIgnoreCase))
                {
                    using (IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream))
                    {
                        result = excelReader.AsDataSet();
                    }
                }
                else if (filename.EndsWith("xlsx", StringComparison.OrdinalIgnoreCase))
                {
                    using (IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream))
                    {
                        result = excelReader.AsDataSet();
                    }
                }
            }

            returnval = result != null && result.Tables[0] != null ? result.Tables[0].Copy() : null;

            return returnval;
        } 
//
///从MS Excel中读取数据,并从其SSRS报告中导出。
///此方法使用ExcelDataReaderhttps://github.com/ExcelDataReader/ExcelDataReader
///避免依赖OleDb Jet或ACE驱动程序。因为我们无法控制安装在上的内容
///客户端机器,我们不能假设它们安装了正确的驱动程序,因此我们将
///使用ExcelDataReader。
/// 
///文件名到Excel(xls或xlsx)文件的路径。
///包含所需数据的DataTable,如果找不到数据,则为null。
专用数据表ReadDataFromUsingExcelReader(字符串文件名)
{
DataTable returnval=null;
数据集结果=null;
使用(FileStream stream=File.Open(filename,FileMode.Open,FileAccess.Read))
{
if(filename.EndsWith(“xls”,StringComparison.ordinallingorecase))
{
使用(IExcelDataReader excelReader=ExcelReaderFactory.CreateBaryReader(流))
{
结果=excelReader.AsDataSet();
}
}
else if(filename.EndsWith(“xlsx”,StringComparison.OrdinalIgnoreCase))
{
使用(IExcelDataReader excelReader=ExcelReaderFactory.CreateOpenXmlReader(流))
{
结果=excelReader.AsDataSet();
}
}
}
returnval=result!=null&&result.Tables[0]!=null?result.Tables[0]。Copy():null;
返回值;
} 

好的,我找到了问题所在