01.
Imports
System.Data.SqlClient
02.
Imports
System.IO
03.
Imports
System.Data
04.
Public
Class
Form2
05.
06.
Dim
objConn
As
SqlConnection
07.
Dim
objCmd
As
SqlCommand
08.
Dim
strConnString
As
String
09.
Dim
cmdConnString
As
String
10.
Private
Sub
Form2_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
11.
12.
13.
strConnString =
"Data Source=PROGRAMMER06-PC;Initial Catalog=ControlEV54_Test;Integrated Security=True"
14.
objConn =
New
SqlConnection(strConnString)
15.
objConn.Open()
16.
17.
18.
End
Sub
19.
20.
Private
Sub
Button2_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
21.
If
objConn.State = ConnectionState.Open
Then
22.
23.
24.
25.
26.
objCmd =
New
SqlCommand(
"ALTER DATABASE ControlEV54_Test SET SINGLE_USER"
, objConn)
27.
objCmd.ExecuteNonQuery()
28.
29.
30.
31.
objCmd =
New
SqlCommand(
"USE ControlEV54 RESTORE DATABASE ControlEV54_Test FROM DISK = 'D:\backup_nid\mybackup.bak'"
, objConn)
32.
objCmd.ExecuteNonQuery()
33.
34.
MessageBox.Show(
"restore สำเร็จ"
)
35.
36.
objCmd =
New
SqlCommand(
"ALTER DATABASE ControlEV54_Test SET MULTI_USER"
, objConn)
37.
objCmd.ExecuteNonQuery()
38.
objConn.Close()
39.
Else
40.
Me
.lblText.Text =
"SQL Server Connect Failed"
41.
End
If
42.
End
Sub
43.
44.
End
Class