Newb问题:我正在开发一个PowerShell脚本,用于存储它的工作数据"使用概述in this blog post.
的方法在本地MS Access数据库文件中一切似乎都在运行,但是当向数据库文件中添加大约500条记录时,后续的$ connection.Close()命令需要超过20秒才能完成。
这是正常的吗?提前谢谢!
编辑 - 以下相关代码:
# setup & open the internal database
$dbCursor = 3
$dbLock = 3
$connection = New-Object -com "ADODB.Connection"
$connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$PSScriptRoot\masterdb.accdb;Persist Security Info=True;"
$recordSet = New-Object -com "ADODB.Recordset"
$connection.Open($connectionString)
$recordSet.Open("SELECT * FROM STUDENTS", $connection, $dbCursor, $dbLock)
# presence check arrays
$dbArray = @()
# import the CSV file
$csvFile = Import-Csv -path "$PSScriptRoot\$cognosDownload"
# populate dbArray from database
$recordSet.MoveFirst()
do {
$dbArray += $recordSet.Fields.Item("SID").Value;
$recordSet.MoveNext()
} until ($recordSet.EOF -eq $True)
# add new records from CSV to database file
foreach($csvLine in $csvFile)
{
# if CSV record is for a new student, add student to database.
if ($dbArray -notcontains $csvLine.SID)
{
$recordSet.AddNew()
$recordSet.Fields.Item("SID").value = $csvLine.SID
$recordSet.Fields.Item("lastName").value = $csvLine.lastName
$recordSet.Fields.Item("firstName").value = $csvLine.firstName
$recordSet.Fields.Item("grade").value = $csvLine.grade
$recordSet.Fields.Item("username").value = Format-Username $csvLine.firstName $csvLine.lastName
$recordSet.Fields.Item("password").value = New-Password
$recordSet.Fields.Item("status").value = "A"
$recordSet.Update()
}
}
# remove (rather large) arrays from memory
Remove-Variable dbArray
#close it all up
$recordSet.Close()
$connection.Close()