@@ -124,11 +124,13 @@ if (-not ([System.IO.Path]::IsPathRooted($fullPath))) {
124124Write-Host " Config $fullPath "
125125
126126try {
127+
128+ $access = New-Object - ComObject Access.Application
129+ $access.OpenCurrentDatabase ($fullPath )
127130
128131# Run procedures from config
129132 if ($config.Procedures -and $config.Procedures.Count -gt 0 ) {
130- $access = New-Object - ComObject Access.Application
131- $access.OpenCurrentDatabase ($fullPath )
133+
132134 foreach ($procedure in $config.Procedures ) {
133135 if (-not $procedure.Name ) {
134136 Write-Error " Procedure name is missing in the configuration."
@@ -152,13 +154,8 @@ try {
152154
153155# Set database properties from config
154156 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 ()
162159
163160 foreach ($property in $config.DatabaseProperties ) {
164161 $propertyName = $property.Name
@@ -186,18 +183,10 @@ catch {
186183}
187184finally {
188185 if ($db ) {
189- if (-not $access ) {
190- # If we used DAO, we need to close the database
191- $db.Close ()
192- }
193186 SafeReleaseComObject $db
194187 Remove-Variable - Name db - ErrorAction SilentlyContinue
195188
196189 }
197- if ($daoEngine ) {
198- SafeReleaseComObject $daoEngine
199- Remove-Variable - Name daoEngine - ErrorAction SilentlyContinue
200- }
201190 if ($access ) {
202191 $access.CloseCurrentDatabase ()
203192 $access.Quit ()
0 commit comments