You can set the connection timeout to the connection level and command level.
Add "Connection Timeout=10" to the connection string. Now connection timeout is 10 seconds.
var connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Connection Timeout=10";
using (var con = new SqlConnection(connectionString))
{
}
Set the of CommandTimeout property to SqlCommand
var connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword";
using (var con = new SqlConnection(connectionString))
{
using (var cmd =new SqlCommand())
{
cmd.CommandTimeout = 10;
}
}