Related:
- SQL error connection
- Network error occurred - Guide
- Oracle sql datediff - Guide
- Cmos checksum error - Guide
- F panel connection - Guide
- Security or firewall might be blocking the connection ✓ - Internet & Social Networks Forum
1 response
using System;
using System.Data.SqlClient;
public class ConnectionTest
{
public static void Main()
{
SqlConnection con = new SqlConnection("Data Source=localhost;" +
"Initial Catalog=Northwind;Integrated Security=SSPI");
con.Open();
Console.WriteLine("Connection is " + con.State.ToString());
con.Close();
Console.WriteLine("Connection is " + con.State.ToString());
}
}
The output clearly indicates whether the connection test is successful:
Connection is Open
Connection is Closed
using System.Data.SqlClient;
public class ConnectionTest
{
public static void Main()
{
SqlConnection con = new SqlConnection("Data Source=localhost;" +
"Initial Catalog=Northwind;Integrated Security=SSPI");
con.Open();
Console.WriteLine("Connection is " + con.State.ToString());
con.Close();
Console.WriteLine("Connection is " + con.State.ToString());
}
}
The output clearly indicates whether the connection test is successful:
Connection is Open
Connection is Closed