Welcome to Sign in | Help
in Search

SMO Issue

Last post 10-26-2007, 3:14 PM by xmldeveloper. 6 replies.
Sort Posts: Previous Next
  •  10-25-2007, 4:29 PM 3090

    SMO Issue

    Am o problema cu Restore la o baza de date folosind SMO ...
  •  10-26-2007, 11:01 AM 3091 in reply to 3090

    Re: SMO Issue

    Private Function ExecuteDBRestore(ByVal DBName As String, _
                                          ByVal BackupPath As String, _
                                          ByVal RestorePath As String) As Boolean

            Dim bResult As Boolean = True
            Dim restore As Restore = Nothing

            Try
                Dim conn As ServerConnection = New ServerConnection(SQLServerName, UserName, Passwd)
                conn.ConnectTimeout = 10000

                Dim srv As Server = New Server(conn)
                Dim db As Database = srv.Databases(DBName)

                If Not db Is Nothing Then srv.KillAllProcesses(DBName)

                restore = New Restore()
                restore.Action = RestoreActionType.Database
                restore.Database = DBName
                restore.Devices.AddDevice(BackupPath, DeviceType.File)
                restore.NoRecovery = True
                restore.ReplaceDatabase = True
                restore.NoRewind = True

                Dim DBLogicalFile As String = restore.ReadFileList(srv).Rows(0)(0) ' for AAIA db is VCDB_Public
                Dim DBLogLogicalFile As String = restore.ReadFileList(srv).Rows(1)(0) ' for AAIA db is VCDB_Public_Log
                restore.RelocateFiles.Add(New RelocateFile(DBLogicalFile, Path.Combine(RestorePath, DBName & "_Data.mdf")))
                restore.RelocateFiles.Add(New RelocateFile(DBLogLogicalFile, Path.Combine(RestorePath, DBName & "_Log.ldf")))

                restore.SqlRestore(srv)
                restore.UnloadTapeAfter = True

                db = srv.Databases(DBName)
                db.SetOnline()

            Catch ex As Exception
                bResult = False
            Finally
                If Not restore Is Nothing Then
                    restore.Devices.Clear()
                End If
            End Try

            Return bResult
        End Function

    In urmatorul exemplu (http://msdn2.microsoft.com/en-us/library/ms162166.aspx) apare:

    Dim rs As Restore
    rs = New Restore
    'Set the NoRecovery property to true, so the transactions are not recovered.
    rs.NoRecovery = True


    Poate problema dvs e la linia restore.NoRecovery = True


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-26-2007, 11:35 AM 3092 in reply to 3091

    Re: SMO Issue

    Dap, de-acolo venea problema. Acuma imi crapa cu succes la restore.SqlRestore(srv)
    Exception-ul suna asa:

    Exception: Restore failed for Server 'TEST\SQLEXPRESS'.
    Source: Microsoft.SqlServer.Smo
    StackTrace:    at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
       at SetupDB.DBInstaller.ExecuteDBRestore(String DBName, String BackupPath, String RestorePath)
    Exception: An exception occurred while executing a Transact-SQL statement or batch.
    Source: Microsoft.SqlServer.ConnectionInfo
    StackTrace:    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
       at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
       at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
       at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
       at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)

    si InnerException-ul:
    Exception: An exception occurred while executing a Transact-SQL statement or batch.
    Source: Microsoft.SqlServer.ConnectionInfo
    StackTrace:    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
       at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
       at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
       at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
       at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
    Exception: Directory lookup for the file "C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Data.mdf" failed with the operating system error 2(The system cannot find the file specified.).
    File 'VCDB_Public' cannot be restored to 'C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Data.mdf'. Use WITH MOVE to identify a valid location for the file.
    Directory lookup for the file "C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Log.ldf" failed with the operating system error 2(The system cannot find the file specified.).
    File 'VCDB_Public_Log' cannot be restored to 'C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Log.ldf'. Use WITH MOVE to identify a valid location for the file.
    Problems were identified while planning for the RESTORE statement. Previous messages provide details.
    RESTORE DATABASE is terminating abnormally.
    Source: .Net SqlClient Data Provider
    StackTrace:    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)

     

  •  10-26-2007, 11:40 AM 3093 in reply to 3092

    Re: SMO Issue

    Aparent se incearca restore pentru fisierele C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Data.mdf si C:\inetpub\wwwroot\TireTrader 4.0\App_Data\AAIA_Log.ldf, fisiere inexistente.
    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-26-2007, 12:01 PM 3094 in reply to 3093

    Re: SMO Issue

    Interesant e ca aceeasi bucata de cod merge pe calculatorul local, dintr-un DLL, si nu merge intr-o masina virtuala cu XP SP2, dintr-un installer( custom action dll )

    I'm damn puzzled ....Surprise

  •  10-26-2007, 2:59 PM 3098 in reply to 3094

    Re: SMO Issue

    Exista acea baza de date pe masina virtuala ?

    Si acea structura de foldere?


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-26-2007, 3:14 PM 3099 in reply to 3098

    Re: SMO Issue

    Dvs incercati sa restaurati o baza de date peste alta.

    Ce returneaza EXEC sp_helpdb 'AAIA' ?

    Folositi Restore.RelocateFiles http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.restore.relocatefiles.aspx


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems