[英]Spreadsheet connection in vb web app
我的客戶要在他們的網站上列出價格表。 我正在嘗試使用電子表格(.xlsx)作為數據源,以便限制數據在網站上出現之前的處理。
該站點在IIS 7上運行。服務器是Windows Server2008。我已經將.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 Office驅動程序,並且根據第二個答案修改了我的連接字符串:
<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>
對於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.