Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get this compile error: "decleration expected" I Dont what wrong now
It highlights all db and End try gives me error it says "End try must be preceded by matching try
please help


VB
Imports System.Data
Imports Emis_Data_layer
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Imports Microsoft.SqlServer.Management
Imports System.Collections.Specialized
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Public Class BACKUP_recovery
    Try
    Dim db As New Database
            db = srv.Databases("My_WorkDB")
    Dim bdi As BackupDeviceItem
            bdi = New BackupDeviceItem("C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\My_WorkDB.bak", DeviceType.File)
    'Define a Restore object variable.
    Dim rs As Restore
            rs = New Restore
            rs.NoRecovery = RestoreActionType.Database
    ' rs.ReplaceDatabase = True       
    'rs.NoRecovery = True
            rs.Devices.Add(bdi)
            rs.Database = "My_WorkDB"
            rs.SqlRestore(srv)
    'Remove the device from the Restore object.
            rs.Devices.Remove(bdi)
            srv.Databases("My_WorkDB").DatabaseOptions.RecoveryModel = RecoveryModel.Full
    Catch ex As Exception
    End Try
 sqlConn.Close()
Posted
Updated 31-Aug-11 1:32am
v2

1 solution

you class should be structured like this

VB
imports system.data
'other imports here

public class SomeClass
  public sub SomeRoutine
  end sub
end class


i.e.

VB
public sub BackUpDB
  Try
   Dim db As New Database
   db = srv.Databases("My_WorkDB")
   Dim bdi As BackupDeviceItem
   bdi = New BackupDeviceItem("C:\Program Files\Microsoft SQL ServerMSSQL.1\MSSQL\Backup\My_WorkDB.bak", DeviceType.File)
   'Define a Restore object variable.
   Dim rs As Restore
   rs = New Restore
   rs.NoRecovery = RestoreActionType.Database
   ' rs.ReplaceDatabase = True
   'rs.NoRecovery = True
   rs.Devices.Add(bdi)
   rs.Database = "My_WorkDB"
   rs.SqlRestore(srv)
   'Remove the device from the Restore object.
   rs.Devices.Remove(bdi)
   srv.Databases("My_WorkDB").DatabaseOptions.RecoveryModel = RecoveryModel.Full
   Catch ex As Exception
   End Try
sqlConn.Close()
end sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900