EF代码首先使用SQL Compact:底层提供程序在打开时失败:找不到数据库文件。检查数据库的路径 [英] EF Code first w/ SQL Compact: Underlying provider failed on open: The database file cannot be found. Check the path to the database

查看:47
本文介绍了EF代码首先使用SQL Compact:底层提供程序在打开时失败:找不到数据库文件。检查数据库的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将失去它。 我很想忘记。

I am about to lose it.  I am seriously about to lose my mind.

我的应用程序工作正常,已停止在特定区域工作。 我的自动化测试在一周前工作正常,已停止工作。

My application, which was working fine, has stopped working in a particular area.  My automated tests, which were working fine a week ago, have stopped working.

问题主要集中在使用Sql Compact 4.0创建具有Entity Framework代码的多个数据库。 

The problem is all centered around creating multiple databases with Entity Framework code first using Sql Compact 4.0. 

简单地说,我创建数据库(基于DbContext的类的实例),我保存,我删除了数据库文件。 我稍后使用相同的文件名创建另一个数据库。   我提到这个工作正常吗? 是的,顺便说一句。 
只是花花公子。

Put simply, I create databases (an instance of a class based on DbContext), I save, I delete the database file.  I create another database using the same file name later.    Did I mention this was working fine?  It was, btw.  Just dandy.

如果我在删除基础文件后不久创建了一个数据库,那么我在上面的错误中遇到了问题。  我意识到如果我创建了我的DbContext类的实例("db")然后调用了Initialize("db.Database.Initialize(true)"),
问题似乎就消失了。

At some point I had had a problem with the error above if I created a database shortly after having deleted the underlying file.  I realized that if I created an instance of my DbContext class ("db") and then called Initialize ("db.Database.Initialize(true)"), the problem seemed to go away.

它现在回来了,它不会消失。 以下是完整的例外:

It's back now, and it won't go away.  Here's the full exception:

System.Data.EntityException:底层提供程序在Open上失败。 ---> System.Data.SqlServerCe.SqlCeException:找不到数据库文件。检查数据库的路径。 [数据源= c:\IDTOffline \ UFT ++ GUI1.tcp]

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeException: The database file cannot be found. Check the path to the database. [ Data Source = c:\IDTOffline\UFT++ GUI1.tcp ]

我现在要哭了。 我现在甚至没有足够的连贯性来更全面地描述我的问题。 也许有人之前见过这个。 晚安。

I'm going to go cry now.  I'm not even coherent enough at the moment to describe my problem more fully than that.  Maybe someone has seen this before.  Good night.

推荐答案

 请注意,它似乎与添加有关支持迁移。 这是我添加的代码使其中断:

 Note that it appears to be related to adding in support for migrations.  This is the code I added that made it break:

var connectionString = BuildConnectionString(fileName);var configuration = new IDTTCDAL.Migrations.Configuration();configuration.TargetDatabase = new DbConnectionInfo(connectionString, "System.Data.SqlServerCe.4.0");var migrator = new DbMigrator(configuration);migrator.Update();




这不是迁移的方式吗? 我还能做些什么来获得迁移支持并使这个问题消失吗?


Is that not the way to do migrations?  Is there something else I could do to have migration support and also make this problem disappear?


这篇关于EF代码首先使用SQL Compact:底层提供程序在打开时失败:找不到数据库文件。检查数据库的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆