我在powershell cmd提示符下运行OLE DB枚举器,看到" Microsoft.ACE.OLEDB.12.0"已列出。但是,当我运行需要使用OLE DB提供程序的程序时,它会给出错误:" Microsoft.ACE.OLEDB.12.0提供程序未在本地计算机上注册。有人可以告诉我为什么它已经存在时找不到提供者。
我下载了Microsoft Database Access Engine 2010 Redistributible,但仍然存在相同的错误
$filepath = 'C:\Users\raoashw\Documents\Incident_Dimension_and_Fact Tables\Incident_Time_Dimension_Table.xlsm'
$connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`"$filepath`";Extended Properties=`"Excel 12.0 Macro;HDR=YES`";"
$qry= 'select * from [backupset$]'
$sqlserver = 'c0003131.itcs.hp.com'
$dbname = 'ads'
$tblname = 'ExcelData_Fill'
function Get-ExcelData
{
param($connString, $qry='select * from [Untitled$]')
$conn = New-Object System.Data.OleDb.OleDBConnection($connString)
$conn.open()
$cmd = New-Object System.Data.OleDb.OleDbCommand($qry,$conn)
$da = New-Object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = New-Object System.Data.DataTable
[void]$da.fill($dt)
$conn.close()
$dt
}
function Write-DataTableToDatabase
{
param($dt,$destServer,$destDb,$destTbl)
$connectionString = "Data Source=$destServer;Integrated Security=true; Initial Catalog=$destdb;"
$bulkCopy= New-Object ("Data.SqlClient.SqlBulkCopy") $connectionString
$bulkCopy.DestinationTableName= "$destTbl"
$bulkCopy.WriteToServer($dt)
}
$dt = Get-ExcelData $connString $qry
Write-DataTableToDatabase $dt $sqlserver $dbname $tblname
有人可以告诉我如何修复此错误吗?