Home Forums Programming SMO/RMO/DMO Detach database, copy to new location, attach database RE: Detach database, copy to new location, attach database

  • I ran this with my info but am still having a problem. Here is the exact script I'm running (copy of yours with names changed):

    Add-Type -AssemblyName “Microsoft.SqlServer.Smo”

    ######################################################################

    $instanceName = 'BRETTW7'

    $databaseName = 'test1'

    ######################################################################

    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName

    $database = $server.Databases[$databaseName]

    Write-Host ("$database has " + $database.LogFiles.Count + " log files.")

    foreach($logFile in $database.LogFiles)

    {

    Write-Host ("`t" + $logFile.Name + " -> " + $logFile.FileName)

    }

    # $server.DetachDatabase(string databaseName,bool updateStatistics) > http://msdn.microsoft.com/en-us/library/ms210177.aspx

    And here is the output and error:

    [test1] has log files.

    The following exception was thrown when trying to enumerate the collection: "Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Cultu

    re=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.".

    At C:\Users\Brett\AppData\Local\Temp\bdd09e9f-9e90-425a-bfc0-3810a9fb614c.ps1:15 char:8

    + foreach <<<< ($logFile in $database.LogFiles)

    + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException

    + FullyQualifiedErrorId : ExceptionInGetEnumerator

    Thanks for you help,

    Brett