I used the following method as the Entity Framework Code First became available:
public virtual void CreateDatabase() { var dbContext = _dbContextLocator.Current; dbContext.Database.Delete(); dbContext.Database.Create(); dbContext.Database.Initialize(true); }
Recently, I noticed that when I hit dbContext.Database.Create() I get the following exception:
Fixed System.Data.SqlServerCe.SqlCeException
Message = The specified table does not exist. [__MigrationHistory]
Source = ADO.NET Data Provider for SQL Server Compact
ErrorCode = -2147467259
HResult = -2147217865
NativeError = 0
StackTrace: in System.Data.SqlServerCe.SqlCeCommand.ProcessResults (Int32 hr)
InnerException:
If I go to "Debugging - Exceptions" and mark "Thrown" for "Excluding the total runtime of the language", this will stop the execution and I will get the above exception. If I remove it, the database seems to be created correctly, but I get four repetitions of the following error statements in the output window:
The first random error like "System.Data.SqlServerCe.SqlCeException" occurred in System.Data.SqlServerCe.dll. The first exception of the type "System.Data.SqlServerCe.SqlCeException" appeared in System.Data.SqlServerCe in System.Data.SqlServerCe. Entity.dll the first random error of type "System.Data.SqlServerCe.SqlCeException" occurred in System.Data.Entity.dll the first random error of type "System.Data.EntityCommandExecutionException" occurred in System.Data.Entity.dll the first random error of type "System.Data.EntityCommandExecutionException" The first exception of type "System.Data.EntityCommandExecutionException" has appeared in System.Data.Entity.dll
Placing a try / catch block around dbContext.Database.Create() has no effect.
My goal is to create a completely empty database and then manually populate it with data. I do not want to use the new Migrations feature for the Entity Framework.
What can I do to eliminate the first random exceptions?
source share