/// <summary>
/// Checks a connection string for validity
/// </summary>
/// <param name="cn">SQL Connection string to validate</param>
/// <returns>True if connection is valid.</returns>
/// <history>
/// [Tim Hibbard] 12/03/2006 Created
/// </history>
public static bool IsValidSQLConnectionString(string cn)
{
bool RV = true;
try
{
if (!cn.Contains("Data Source"))
{
throw new MissingMemberException("Missing Data Source");
}
if (!cn.Contains("Initial Catalog"))
{
throw new MissingMemberException("Missing Initial Catalog");
}
if (!cn.Contains("User ID"))
{
throw new MissingMemberException("Missing User ID");
}
if (!cn.Contains("Password"))
{
throw new MissingMemberException("Missing Password");
}
string[] contents = cn.Split(char.Parse(";"));
if (!contents[0].StartsWith("Data Source"))
{
throw new MissingMemberException("Missing Data Source");
}
if (!contents[1].StartsWith("Initial Catalog"))
{
throw new MissingMemberException("Missing Initial Catalog");
}
if (!contents[2].StartsWith("User ID"))
{
throw new MissingMemberException("Missing User ID");
}
if (!contents[3].StartsWith("Password"))
{
throw new MissingMemberException("Missing Password");
}
}
catch (Exception)
{
RV = false;
}
return RV;
}