none
How to backup a SQL Server Database connecting from windows 7 using powershell ?

    Question

  • I did debug it line by line and it breaks when doing the connection and not able to list the databases.

    PS C:\scripts\SQL> $ServerName = "UPIVCUMDB2" PS C:\scripts\SQL> $con = New-Object Microsoft.SqlServer.Management.Common.ServerConnection -Arg $ServerName, "sa", "pswd" PS C:\scripts\SQL> $MySQL = [Microsoft.SqlServer.Management.Smo.Server] $con PS C:\scripts\SQL> $MySQL.Databases.Name The following exception occurred while trying to enumerate the collection: "Failed to connect to server UPIVCUMDB2.". At line:1 char:1 + $MySQL.Databases + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException + FullyQualifiedErrorId : ExceptionInGetEnumerator

    But through the following code i am able to list the databases but not able to backup:

    PS C:\scripts\SQL> $ServerName = "UPIVCUMDB2"
    PS C:\scripts\SQL> $MySQL = new-object('Microsoft.SqlServer.Management.Smo.Server') $ServerName
    PS C:\scripts\SQL> $MySQL.Databases.Name
    master
    model
    msdb
    tempdb
    UMDB2
    VCDB2

    And the error is this one

    Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server 'UPIVCUMDB2'. "
    At C:\scripts\SQL\BAK.ps1:23 char:3
    +         $DatabaseBackup.SqlBackup($MySQL)
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : FailedOperationException
    
    Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server 'UPIVCUMDB2'. "
    At C:\scripts\SQL\BAK.ps1:23 char:3
    +         $DatabaseBackup.SqlBackup($MySQL)
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : FailedOperationException


    GE RF

    Friday, October 18, 2013 9:09 PM

Answers

All replies