Пример #1
0
 public static bool TryOpenConnections(
     ISqlObjectFactory factory,
     out int number,
     out string message,
     params string[] connectionStrings)
 {
     try
     {
         connectionStrings.ForEach(connectionString =>
         {
             var sqlConnection = factory.CreateSqlConnection(connectionString);
             sqlConnection.Open();
             sqlConnection.Close();
         });
         number  = 0;
         message = string.Empty;
         return(true);
     }
     catch (DbException e)
     {
         number  = factory.SqlErrors.ErrorCode(e);
         message = e.Message;
         return(false);
     }
     catch (Exception e)
     {
         number  = -1;
         message = e.Message;
         return(false);
     }
 }
Пример #2
0
        private ISqlConnection CreateAndOpenConnection(
            ISqlObjectFactory factory)
        {
            var sqlConnection = factory.CreateSqlConnection(
                connectionString: SqlContainer.ConnectionString);

            sqlConnection.Open();
            return(sqlConnection);
        }