diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index 309c9aeefc..baae19801d 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -25,6 +25,7 @@ namespace Umbraco.Core #region Singleton private static readonly Lazy lazy = new Lazy(() => new DatabaseContext()); private string _connectionString; + private string _providerName; /// /// Gets the current Database Context. @@ -72,17 +73,20 @@ namespace Umbraco.Core { get { - var providerName = "System.Data.SqlClient"; + if (string.IsNullOrEmpty(_providerName) == false) + return _providerName; + + _providerName = "System.Data.SqlClient"; if (ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName] != null) { if (!string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName)) - providerName = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName; + _providerName = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName; } else { throw new InvalidOperationException("Can't find a connection string with the name '" + GlobalSettings.UmbracoConnectionName + "'"); } - return providerName; + return _providerName; } } @@ -125,7 +129,8 @@ namespace Umbraco.Core engine.CreateDatabase(); } - Initialize(); + + Initialize(providerName); } /// @@ -138,7 +143,7 @@ namespace Umbraco.Core public void ConfigureDatabaseConnection(string connectionString) { SaveConnectionString(connectionString, connectionString, string.Empty); - Initialize(); + Initialize(string.Empty); } /// @@ -172,7 +177,7 @@ namespace Umbraco.Core } SaveConnectionString(connectionString, appSettingsConnection, providerName); - Initialize(); + Initialize(providerName); } /// @@ -193,9 +198,11 @@ namespace Umbraco.Core : new ConnectionStringSettings(GlobalSettings.UmbracoConnectionName, connectionString, providerName); + _connectionString = connectionString; + _providerName = providerName; + //Set the connection string in appsettings used in the legacy datalayer GlobalSettings.DbDsn = appSettingsConnection; - //ConfigurationManager.ConnectionStrings.Add(conectionString); var webConfig = new WebConfigurationFileMap(); var vDir = GlobalSettings.FullpathToRoot; @@ -224,7 +231,6 @@ namespace Umbraco.Core } xml.Save(fileName); - ConfigurationManager.RefreshSection("connectionStrings"); } /// @@ -270,5 +276,23 @@ namespace Umbraco.Core _configured = false; } } + + internal void Initialize(string providerName) + { + if (providerName.StartsWith("MySql")) + { + SyntaxConfig.SqlSyntaxProvider = MySqlSyntax.Provider; + } + else if (providerName.Contains("SqlServerCe")) + { + SyntaxConfig.SqlSyntaxProvider = SqlCeSyntax.Provider; + } + else + { + SyntaxConfig.SqlSyntaxProvider = SqlServerSyntax.Provider; + } + + _configured = true; + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs index 3fb85765cb..473b6e15b5 100644 --- a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs +++ b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Data.SqlServerCe; using Umbraco.Core.Persistence.Migrations.Initial; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.SqlSyntax.ModelDefinitions; diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs index 87f55bf3e7..d4bce64776 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs @@ -179,7 +179,9 @@ namespace umbraco.presentation.install.steps Helper.setProgress(20, "Connection opened", ""); - DatabaseContext.Current.Database.Initialize(); + var database = new Database(DatabaseContext.Current.ConnectionString, + DatabaseContext.Current.ProviderName); + database.Initialize(); Helper.setProgress(90, "Refreshing content cache", "");