src/Shared/EntityFramework/Internal/DatabaseOperations.cs
// <summary>
// Used a delegate to do the actual existence check once an ObjectContext has been obtained.
// This is factored in this way so that we do the same thing regardless of how we get to
// having an ObjectContext.
// </summary>
Used a delegate to do the actual existence check once an ObjectContext has been obtained.
This is factored in this way so that we do the same thing regardless of how we get to
having an ObjectContext.
Used a delegate to do the actual existence check once an ObjectContext has been obtained . This is factored in this way so that we do the same thing regardless of how we get to having an ObjectContext .
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        public virtual bool Exists(DbConnection connection, int? commandTimeout, Lazy<StoreItemCollection> storeItemCollection)
        {
            DebugCheck.NotNull(connection);
            if (connection.State == ConnectionState.Open)
            {
                return true;
            }
            try
            {
                return DbProviderServices.GetProviderServices(connection)
                    .DatabaseExists(connection, commandTimeout, storeItemCollection);
            }
            catch
            {
                try
                {
                    connection.Open();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] public virtual bool Exists ( DbConnection connection , int ? commandTimeout , Lazy < StoreItemCollection > storeItemCollection ) { DebugCheck . NotNull ( connection ) ; if ( connection . State == ConnectionState . Open ) { return true ; } try { return DbProviderServices . GetProviderServices ( connection ) . DatabaseExists ( connection , commandTimeout , storeItemCollection ) ; } catch { try { connection . Open ( ) ; return true ; } catch ( Exception ) { return false ; } finally { connection . Close ( ) ; } } }
Used a delegate to do the actual existence check once an ObjectContext has been obtained.
Used a delegate to do the actual existence check once an ObjectContext has been obtained .
// In situations where the user does not have access to the master database // the above DatabaseExists call fails and throws an exception.  Rather than // just let that exception escape to the caller we instead try a different // approach to see if the database really does exist or not.  The approach // is to try to open a connection to the database.  If this succeeds then // we know that the database exists.  If it fails then the database may // not exist or there may be some other issue connecting to it.  In either // case for the purpose of this call we assume that it does not exist and // return false since this functionally gives the best experience in most // scenarios.
connection
DbConnection
commandTimeout
int?
storeItemCollection
Lazy<StoreItemCollection>