'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册 VB.net



我正在做一个项目,上传一个Excel文件,然后在页面上查看它,继续使用vb.net编辑…根据这个代码

If FileUpload1.HasFile Then
Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim fileExtension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)

'Dim folderPath As String = Server.MapPath("~/Downloads/") & "Clients" & ""
Dim folderPath As String = Server.MapPath("~/Downloads/") & Session("CustName") & "/Clients"
If Not Directory.Exists(folderPath) Then
'If Directory (Folder) does not exists Create it.
Directory.CreateDirectory(folderPath)
End If
FileUpload1.SaveAs(folderPath & Regex.Replace(SQLHandleAps(Path.GetFileNameWithoutExtension(FileUpload1.FileName)), "[[]\^$.|?*+(){}%,;><!@#&-+]", "") & Path.GetExtension(FileUpload1.FileName))
Dim fileLocation As String = folderPath & Regex.Replace(SQLHandleAps(Path.GetFileNameWithoutExtension(FileUpload1.FileName)), "[[]\^$.|?*+(){}%,;><!@#&-+]", "") & Path.GetExtension(FileUpload1.FileName)
'     FileUpload1.SaveAs(fileLocation)
If fileExtension = ".xls" Then
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileLocation & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
LblError.Visible = False
ElseIf fileExtension = ".xlsx" Then
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileLocation & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
LblError.Visible = False
Else
LblError.CssClass = "ErrorContent"
LblError.Text = "Your file selected Not Excel file"
LblError.Visible = True
Exit Sub
End If
RequiredFieldValidator1.Enabled = True
Dim con As New OleDbConnection(connectionString)
Dim cmd As New OleDbCommand()
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = con
Dim dAdapter As New OleDbDataAdapter(cmd)
Dim dtExcelRecords As New DataTable()
con.Open()
Dim dtExcelSheetName As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim getExcelSheetName As String = dtExcelSheetName.Rows(0)("Table_Name").ToString()
cmd.CommandText = "Select * FROM [" & getExcelSheetName & "]"
dAdapter.SelectCommand = cmd
dAdapter.Fill(dtExcelRecords)
Dim ExlRecord = dtExcelRecords.Rows
con.Close()
GridView1.DataSource = dtExcelRecords
GridView1.DataBind()
End If

它工作得很好,但是当我将项目发布到web时,我有这个错误

'Microsoft.ACE.OLEDB.12.0'提供程序未在本地机器上注册

您需要在运行网站的机器上安装ACE数据库引擎的副本。

此外,您需要匹配访问数据引擎的位大小。你没有提到你是将站点运行为x64位(目前默认),还是想强制/设置应用程序池以x32位运行。

所以,当你不需要安装office/access时,你甚至不需要安装access运行时?(两个都可以)

你可以选择最"轻量级"的你至少需要安装ACE数据引擎

此外,不要使用"any"如果您使用的是x32位版本的ACE,请确保将其设置为x32位运行,或者设置为x64位运行,如果您使用的是x64位版本的ACE。

所以,你需要处理两个问题:

将项目强制为给定的位大小。因此,不要使用任何cpu,而是使用x86(用于x32位Access/ACE),并使用x64位Access/ACE。

所以,虽然你可以安装office/access,或者安装access运行时,一个更好的选择是只安装access数据引擎(access也使用它)。

您可以在这里找到ACE数据引擎的副本:

https://www.microsoft.com/en-us/download/details.aspx?id=54920

确保你下载并安装了正确的版本(可能是x64位版本,因为这是你默认的IIS web服务器(x64位)。

如前所述,这也意味着您不想使用"任何cpu"。,但根据您安装的访问数据引擎(ACE)的当前位大小强制项目编译为x32或x64位。

相关内容

最新更新