I have a project using SqlServerCe.3.5 with EntityFramework 6. I want to change the database to PostgreSQL so I changed the configuration
From:
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlServerCe.3.5" type="System.Data.Entity.SqlServerCompact.Legacy.SqlCeProviderServices, EntityFramework.SqlServerCompact.Legacy" />
</providers>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.3.5" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="Model1Container" connectionString="Data Source=<.. DB.sdf ...>" providerName="System.Data.SqlServerCe.3.5" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.3.5" />
<add name="Microsoft SQL Server Compact Data Provider 3.5" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
To:
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<connectionStrings>
<add name="Model1Container" connectionString="Server=localhost;<...>" providerName="Npgsql" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
When I run my software with the new config file I got the following error:
DbMigrator migrator = new DbMigrator(new Migrations.Configuration());
var latestMigration = migrator.GetLocalMigrations().Last();
var charPos = latestMigration.IndexOf("_");
var migrationName = latestMigration.Substring(charPos + 1, latestMigration.Length - charPos - 1);
migrator.Update(migrationName); // <<< it crashes here!!
Exception:
The ADO.NET provider with invariant name 'System.Data.SqlServerCe.3.5' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.ThrowOnNonWarningErrors() at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable'1 xmlReaders, IEnumerable'1 sourceFilePaths) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader..ctor(IEnumerable'1 xmlReaders, IEnumerable'1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable'1 xmlReaders, IEnumerable'1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer'2& cachedCTypeFunction) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable'1 xmlReaders) at System.Data.Entity.Utilities.XDocumentExtensions.GetStorageMappingItemCollection(XDocument model, DbProviderInfo& providerInfo) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) at System.Data.Entity.Migrations.DbMigrator.IsModelOutOfDate(XDocument model, DbMigration lastMigration) at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable'1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable'1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.b__b() at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) at DAL.Session.Init() in <...>
I got this error message but my PostgreSQL database is created with all the tables defined in my CodeFirst EntityFramework.
In the machine.config
there is no SqlServerCe nor Npgsql defined.
Is it possible that somewhere hidden there is a settings I don't see? I made a text search on all config and project files and I don't see any possible reason.
System.Data.SqlCe
namespace anywhere? – Joel CoehoornSqlServerCe
and I can build. – doodoromaSystem.Data.Entity.Migrations.Infrastructure.EdmModelDiffer
– doodoroma