01.
Public
Function
DbConnect()
As
Boolean
02.
03.
On
Error
GoTo
error_handle
04.
05.
06.
If
gConn.State = ConnectionState.Closed
Then
07.
gConn =
New
SqlConnection
08.
With
gConn
09.
.ConnectionString =
"Data Source=N-EF4D3A3330684;Initial Catalog=account;Integrated Security=True"
10.
11.
gConn.Open()
12.
13.
14.
End
With
15.
End
If
16.
DbConnect =
True
17.
Exit
Function
18.
error_handle:
19.
MsgBox(Err.Description & Chr(10) &
"Error: Can not connect to database"
& _
20.
"Please contact administrator"
, _
21.
vbOKOnly,
"ConnectDB Error"
)
22.
DbConnect =
False
23.
End
Function
24.
End
Module