Ok, reverting the correct commit this time: Revert "Fixes database context issue during startup when there is no db configured"

This commit is contained in:
Shannon
2017-02-07 12:49:26 +11:00
parent fa8f3985b8
commit f816a63b54
3 changed files with 4 additions and 21 deletions

View File

@@ -98,14 +98,7 @@ namespace Umbraco.Core
/// </remarks>
public virtual UmbracoDatabase Database
{
get
{
if (IsDatabaseConfigured == false)
{
throw new InvalidOperationException("Cannot create a database instance, there is no available connection string");
}
return _factory.CreateDatabase();
}
get { return _factory.CreateDatabase(); }
}
/// <summary>
@@ -171,7 +164,7 @@ namespace Umbraco.Core
}
else
{
throw new NullReferenceException("Can't find a connection string with the name '" + Constants.System.UmbracoConnectionName + "'");
throw new InvalidOperationException("Can't find a connection string with the name '" + GlobalSettings.UmbracoConnectionName + "'");
}
return _providerName;
}

View File

@@ -167,12 +167,12 @@ namespace Umbraco.Core.Persistence
var providerName = Constants.DatabaseProviders.SqlServer;
if (ConfigurationManager.ConnectionStrings[connectionStringName] != null)
{
if (string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName) == false)
if (!string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName))
providerName = ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName;
}
else
{
throw new NullReferenceException("Can't find a connection string with the name '" + connectionStringName + "'");
throw new InvalidOperationException("Can't find a connection string with the name '" + connectionStringName + "'");
}
// Store factory and connection string

View File

@@ -59,16 +59,6 @@ namespace Umbraco.Core
//And now we can dispose of our startup handlers - save some memory
ApplicationEventsResolver.Current.Dispose();
// after Umbraco has started there is a database in "context" and that context is
// going to stay there and never get destroyed nor reused, so we have to ensure that
// the database is disposed (which will auto-remove it from context).
if (ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
{
var database = ApplicationContext.Current.DatabaseContext.Database;
if (database != null) // never to happen... unless in weird tests
ApplicationContext.Current.DatabaseContext.Database.Dispose();
}
}
/// <summary>