【问题标题】:Spreadsheet connection in vb web appvb Web应用程序中的电子表格连接
【发布时间】:2011-04-11 14:52:09
【问题描述】:

我的客户希望他们的价目表出现在他们的网站上。我正在尝试使用电子表格 (.xlsx) 作为数据源,以便在数据出现在网站上之前限制对其进行处理。

该站点在 IIS 7 上运行。服务器是 Windows Server 2008。我已将其上的 .NET Framework 更新为 4.0。

它没有安装任何 Office 软件包,我有一种预感,这就是我的问题所在,但我真的很想确定。

这是我得到的错误文本:

System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() at Products.Page_Load(Object sender, EventArgs e) in C:\HostingSpaces\webbuddies\waterinc.webbuddies.co.za\wwwroot\Products.aspx.vb:line 14

这是我的代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Here's the connection string as defined in web.config:
' <connectionStrings>
'     <add name="xlsx" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=App_Data/Pricelist.xlsx;Extended Properties=Excel 8.0;" />
' </connectionStrings>
    Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("xlsx").ConnectionString)

    ' The spreadsheet has 4 sheets in it, 1 for each category on the client's pricelist.
    Try
        con.Open()

        Dim dsWater As DataSet
        Dim daWater As New OleDbDataAdapter
        daWater.SelectCommand = New OleDbCommand("SELECT * FROM Water", con)

        Dim dsJuice As DataSet
        Dim daJuice As New OleDbDataAdapter
        daJuice.SelectCommand = New OleDbCommand("SELECT * FROM FruitJiuce", con)

        Dim dsMix As DataSet
        Dim daMix As New OleDbDataAdapter
        daMix.SelectCommand = New OleDbCommand("SELECT * FROM MuffinMix", con)

        Dim dsMisc As DataSet
        Dim daMisc As New OleDbDataAdapter
        daMisc.SelectCommand = New OleDbCommand("SELECT * FROM Miscellaneous", con)

        daWater.Fill(dsWater, "Water")
        daJuice.Fill(dsJuice, "FruitJuice")
        daMix.Fill(dsMix, "MuffinMix")
        daMisc.Fill(dsMisc, "Miscellaneous")

        rptWater.DataSource = dsWater : rptWater.DataBind()
        rptJuices.DataSource = dsJuice : rptJuices.DataBind()
        rptMixes.DataSource = dsMix : rptMixes.DataBind()
        rptMisc.DataSource = dsMisc : rptJuices.DataBind()

        con.Close()
    Catch ex As Exception
        errorMessage = ex.ToString
        lblResponse.Text = "Could not connect to one or more data sources required to display the " & _
            "pricelist. Please contact the webmaster." & vbCrLf & errorMessage
        lblResponse.ForeColor = Drawing.Color.Red
    End Try
End Sub

编辑 1
自发布以来,我已经通过第一个答案中的链接在服务器上安装了 2007 办公驱动程序,并且我根据第二个答案修改了我的连接字符串:

<connectionStrings>
    <add name="xlsx" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source=App_Data/Pricelist.xlsx; Extended Properties=Excel 12.0 Xml; HDR=YES;"/>
</connectionStrings>

【问题讨论】:

    标签: asp.net excel ado jet ms-jet-ace


    【解决方案1】:

    【讨论】:

    • 我在服务器上安装了,没有效果
    【解决方案2】:

    对于 XLSX 文件,您需要像这样修改连接字符串。

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";
    

    更多信息 - http://connectionstrings.com/excel-2007

    【讨论】:

    • 我从 Provider=Microsoft.ACE.OLEDB.21.0; 开始,但现在当我输入此内容时,我突然想到我当时没有在服务器上安装 2007 办公驱动程序...
    • 您使用的是 2003 / 2007 / 2010 哪个版本的 Excel?我认为 2007 年是 Microsoft.ACE.OLEDB.12.0,2010 年是 Microsoft.ACE.OLEDB.14.0。
    猜你喜欢
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多