01.
Private
Sub
DoProcess(activity
As
String
)
02.
Try
03.
04.
05.
06.
07.
08.
09.
10.
Dim
command
As
String
=
""
""
+
"SqlLocalDB.exe"
&
""
""
11.
Dim
info
As
New
ProcessStartInfo(command, (
" "
& activity &
" "
) +
"ชื่อ DATABASE "
)
12.
Dim
p
As
New
Process()
13.
p.StartInfo = info
14.
p.StartInfo.UseShellExecute =
False
15.
p.StartInfo.RedirectStandardOutput =
True
16.
p.StartInfo.RedirectStandardError =
True
17.
p.Start()
18.
p.WaitForExit()
19.
Dim
reader
As
StreamReader = p.StandardOutput
20.
Dim
output
As
String
= reader.ReadToEnd()
21.
reader.Close()
22.
If
output.Length = 0
Then
23.
reader = p.StandardError
24.
Dim
[error]
As
String
= reader.ReadToEnd()
25.
reader.Close()
26.
MsgBox([error] &
" ไม่สามารถสร้างการติดต่อกับ Database ได้"
, MsgBoxStyle.Critical)
27.
Else
28.
MsgBox(output &
" สร้างการติดต่อกับ Database เรียบร้อยแล้ว"
, MsgBoxStyle.Information)
29.
End
If
30.
31.
Catch
ex
As
Exception
32.
MessageBox.Show(
"ไม่สามารถเชื่อมต่อได้ กรุณาลองปิดโปรแกรมแล้วทำการสร้างการเชื่อมต่อใหม่อีกครั่ง"
,
"Error"
, MessageBoxButtons.OK, MessageBoxIcon.[
Error
])
33.
34.
35.
36.
End
Try
37.
End
Sub