Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Sub CreateMyConnection()
ProdConn = ProdServer.ConnectionContext
ProdConn.ServerInstance = "<MyServer>, <MyPort>"
End Sub
CreateMyConnection()
Dim dbname As Database
For Each dbname In ProdServer.Databases
If Not dbname.IsSystemObject And Not dbname.IsDatabaseSnapshot Then
DatabaseList.Items.Add(dbname.Name)
End If
Next
'The above code cycles through the list of all databases on the server and displays
'them in the ListBox. It does NOT include system databases or existing snapshots
Try
CreateSnapshot_Click(DatabaseList.SelectedItem.ToString, e)
Catch MyExeception As System.NullReferenceException
'Call MsgBox("You must select a database to continue.")
End Try
'The above calls the button event which will create the snapshot
CloseObjects()
'The above calls the public sub CloseObjects() to clear out all variables
dbname = Nothing
'The above clears out the variable dbname
Dim SnapshotCode As String
Dim DBToSnapShot As String = DatabaseList.SelectedItem.ToString
'Prepares my variables to store the database name as well as the T-SQL to snapshot
SnapshotCode = "CREATE DATABASE " & DBToSnapShot & "_SS ON (NAME=" _
& DBToSnapShot & "_Data,FILENAME='K:\SQL_DATA\" & DBToSnapShot & ".SNAP') AS SNAPSHOT OF " _
& DBToSnapShot
'The above sets the T-SQL, including the drive path, of where the Snapshot will go
'MsgBox("The Snapshot Code is translated as " & SnapshotCode)
'The above MsgBox is used for debugging the Snapshot Code
Dim MySQLConn As New SqlConnection("data source=<MyServer>, <MyPort>;initial catalog=master;Trusted_Connection = Yes")
Dim command As New SqlCommand(SnapshotCode, MySQLConn)
Dim QueryReturnedValue As Integer
'The above code sets up a new SQL Connection, as well as setting the query
'to use the above connection, and accepts a return code for verifying
'success or failure.
MySQLConn.Open()
'Above opens the SQL Connection
QueryReturnedValue = command.ExecuteNonQuery()
'Above executes the T-SQL Snapshot command
If QueryReturnedValue = 0 Then
MsgBox("Snapshot Creation failed. Try again or contact a DBA for further instructions.")
Else
MsgBox("Snapshot Creation succeeded. Chose another database to snapshot or close this form.")
End If
'User-Friendly response to button click
MySQLConn.Close()
'Close out connection (just good programming)
MySQLConn = Nothing
command = Nothing
QueryReturnedValue = Nothing
SnapshotCode = Nothing
DBToSnapShot = Nothing
'Empty all variables for trash collection
Public Sub CloseObjects()
ProdServer = Nothing
ProdConn = Nothing
' Me.Close()
End Sub