/// <summary> /// Проверка подключения к БД /// </summary> /// <returns></returns> public static bool CheckConnection() { try { using (SqlConnection connection = new SqlConnection(ConnectionStringDataBase.Read())) { int dircount = 0; connection.Open(); SqlCommand cmd = new SqlCommand("SELECT count(*) FROM sys.Tables", connection); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { dircount = Convert.ToInt32(reader[0]); } } if (dircount > 0) { return(true); } else { return(false); } } } catch { return(false); } }
/// <summary> /// Возвращает строку подключения /// </summary> /// <returns>string </returns> public static string ConnectionString() { try { ConfigTxt config = new ConfigTxt(); return(ConnectionStringDataBase.Read()); } catch (Exception ex) { Log.Write(ex, " - Ошибкав с троке подключения !!!"); throw ex; } }