Hi there, im new to VB and am trying to work out how i can check that my database connection info is correct before i connect.
error example with incorrect info: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Public Sub SQL_Connect()
ConStr = "data source=" & DB_Server & "; initial catalog=" & DB_Name & ";" + _
"User ID=" & DB_User & "; pwd=" & DB_Pass & "; Integrated Security=SSPI"
Private Sub B_Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_Go.Click
DB_Server = TB_S.Text
DB_Name = TB_D.Text
DB_User = TB_U.Text
DB_Pass = TB_P.Text
If DB_Server = "" Or DB_Name = "" Or DB_User = "" Or DB_Pass = "" Then
MessageBox.Show("You must fill out all fields", "ERROR")
ElseIf B_Go.Text = "CONNECT" Then
Timer.Enabled = True
B_Go.Text = "DISCONNECT"
B_Go.Text = "CONNECT"
Timer.Enabled = False