コード例 #1
0
ファイル: StatusApp.cs プロジェクト: Valerch1k/CapitalPrice
 /// <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);
     }
 }
コード例 #2
0
 /// <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;
     }
 }