Imports System.Data.SqlClient Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim SqlConn As New SqlConnection Dim SqlConnStr As String = "Server=<Server Name/IP>;Database=<Database Name>;Integrated Security=True" If SqlConn.State = ConnectionState.Closed Then SqlConn.ConnectionString = SqlConnStr Try SqlConn.Open() MessageBox.Show("Succsessfull DB Connnection", "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBox.Show("Invalid DB SqlConnnection" + vbCrLf + Err.Description, "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub End Class
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlConnection SqlConn = new SqlConnection(); string SqlConnStr = "Server=<Server Name/IP>;Database=<Database Name>;Integrated Security=True"; if (SqlConn.State == ConnectionState.Closed) { SqlConn.ConnectionString = SqlConnStr; try { SqlConn.Open(); MessageBox.Show("Succsessfull DB Connnection", "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Invalid DB SqlConnnection" + Environment.NewLine + ex.Message, "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
Imports System.Data.SqlClient Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim SqlConn As New SqlConnection Dim SqlConnStr As String = "Data Source=<Server Name/IP>;Database=<Database Name>;Persist Security Info=True;User ID=<Username>;Password=<Password>" If SqlConn.State = ConnectionState.Closed Then SqlConn.ConnectionString = SqlConnStr Try SqlConn.Open() MessageBox.Show("Succsessfull DB Connnection", "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBox.Show("Invalid DB SqlConnnection" + vbCrLf + Err.Description, "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub End Class
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlConnection SqlConn = new SqlConnection(); string SqlConnStr = "Data Source=<Server Name/IP>;Database=<Database Name>;Persist Security Info=True;User ID=<Username>;Password=<Password>"; if (SqlConn.State == ConnectionState.Closed) { SqlConn.ConnectionString = SqlConnStr; try { SqlConn.Open(); MessageBox.Show("Succsessfull DB Connnection", "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Invalid DB SqlConnnection" + Environment.NewLine + ex.Message, "DB Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
For more connection string assistance visit: http://www.connectionstrings.com/
Last Updated on October 26, 2015