首页 > 解决方案 > Powershell创建microsoft access数据库错误

问题描述

我在 windows powershell 中运行以下代码:

Function Create-DataBase($Db){


$application = New-Object -ComObject Access.Application
 $application.NewCurrentDataBase($Db,10)
 $application.CloseCurrentDataBase()
 $application.Quit()
} #End Create-DataBase


#$dbname = Read-Host -Prompt 'Input your database  name'

# database file location
$Db = 'C:\new.mdb'
If(Test-Path $Db){
    Write-Host 'DB already exists' -fore green
}else{
    Create-DataBase $Db
}

但得到以下错误,

使用“5”参数调用“NewCurrentDatabase”的异常:“尝试创建数据库时发生错误。” 在 E:\Mahmood\test2.ps1:3 char:33 + $application.NewCurrentDataBase <<<< ($Db,10) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

使用“0”参数调用“CloseCurrentDatabase”的异常:“您输入的表达式引用了一个已关闭或不存在的对象。” 在 E:\Mahmood\test2.ps1:4 char:35 + $application.CloseCurrentDataBase <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

任何人都知道出了什么问题。

标签: powershellms-access

解决方案


推荐阅读