'Form1.vb
Public Class Form1
Dim SQL As New SQLControl
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If SQL.HasConection = True Then
MessageBox.Show("seccesfully connected")
End If
End Sub
End Class
'SQLControl.vb
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class SQLControl
Public SQLCon As New SqlConnection With {.ConnectionString = "Server=MSDN-SPECIAL\SQLEXPRESS;Database=test;User=sa;Pwd=1111;"}
Public SQLCmd As SqlCommand
Public Function HasConection() As Boolean
Try
SQLCon.Open()
SQLCon.Close()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
End Function
End Class