@@ -124,11 +124,13 @@ if (-not ([System.IO.Path]::IsPathRooted($fullPath))) {
124
124
Write-Host " Config $fullPath "
125
125
126
126
try {
127
+
128
+ $access = New-Object - ComObject Access.Application
129
+ $access.OpenCurrentDatabase ($fullPath )
127
130
128
131
# Run procedures from config
129
132
if ($config.Procedures -and $config.Procedures.Count -gt 0 ) {
130
- $access = New-Object - ComObject Access.Application
131
- $access.OpenCurrentDatabase ($fullPath )
133
+
132
134
foreach ($procedure in $config.Procedures ) {
133
135
if (-not $procedure.Name ) {
134
136
Write-Error " Procedure name is missing in the configuration."
@@ -152,13 +154,8 @@ try {
152
154
153
155
# Set database properties from config
154
156
if ($config.DatabaseProperties -and $config.DatabaseProperties.Count -gt 0 ) {
155
- if ($access ) {
156
- $db = $access.CurrentDb ()
157
- }
158
- else { # use DAO.Database
159
- $daoEngine = New-Object - ComObject DAO.DBEngine.120
160
- $db = $daoEngine.OpenDatabase ($fullPath )
161
- }
157
+
158
+ $db = $access.CurrentDb ()
162
159
163
160
foreach ($property in $config.DatabaseProperties ) {
164
161
$propertyName = $property.Name
@@ -186,18 +183,10 @@ catch {
186
183
}
187
184
finally {
188
185
if ($db ) {
189
- if (-not $access ) {
190
- # If we used DAO, we need to close the database
191
- $db.Close ()
192
- }
193
186
SafeReleaseComObject $db
194
187
Remove-Variable - Name db - ErrorAction SilentlyContinue
195
188
196
189
}
197
- if ($daoEngine ) {
198
- SafeReleaseComObject $daoEngine
199
- Remove-Variable - Name daoEngine - ErrorAction SilentlyContinue
200
- }
201
190
if ($access ) {
202
191
$access.CloseCurrentDatabase ()
203
192
$access.Quit ()
0 commit comments