Here is an example of a small console application that will cycle through the list of connections and try to connect to each, to report success or failure. Ideally, you might want to expand this to read connection strings from a file in the list , but this will hopefully get you started.
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
namespace SQLServerChecker
{
class Program
{
static void Main(string[] args)
{
IDictionary<string, string> connectionStrings = new Dictionary<string, string>();
connectionStrings.Add("Sales Database", "< connection string >");
connectionStrings.Add("QA Database", "< connection string >");
foreach (string databaseName in connectionStrings.Keys)
{
try
{
string connectionString = connectionStrings[databaseName];
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connected to {0}", databaseName);
}
}
catch (Exception ex)
{
Console.WriteLine("FAILED to connect to {0} - {1}", databaseName, ex.Message);
}
}
Console.WriteLine("Press any key to finish.");
Console.ReadKey();
}
}
}
source
share