SQL Server CE Entity Framework代码优先,指定的连接未指定初始目录或AttachDbFileName

问题描述

我有一个使用代码优先方法与SQL Server CE和EF一起使用的桌面应用程序,我有大量的用户在使用它。

我要传递给 DbContext 类构造函数的连接字符串,

@"Data Source=" + Path.Combine("Path to local app data","Databasename.sdf") + ";Password=mypassword"

但是在一台Windows 7 SP1(32位)计算机上,出现以下错误:

System.InvalidOperationException:无法完成操作。提供的SqlConnection没有指定初始目录或AttachDBFileName。

在System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection,String&databaseName,String&dataFileName,String&logFileName)
在System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection连接,可空1 commandTimeout,StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection,Nullable 1 commandTimeout,StoreItemCollection storeItemCollection)
在System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()处
在System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection连接)处
在System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(操作mustSucceedToKeepDatabase)
在System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)处
位于System.Data.Entity.MigrateDatabaseToLatestVersion 2.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf 1.b__e()
在System.Data.Entity.Internal.InternalContext.PerformInitializationAction(动作)上
在System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
在System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c)
在System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action 1操作处)
在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(TypeEntityType)
位于System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet 1.get_InternalContext()
位于System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Any[TSource](IQueryable 1源)
在GCMApiSDK.DataService.d__12.MoveNext()
---从之前引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)上
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上
在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)处
在GCMApiSDK.AuthenticationDialog上。 d__11.MoveNext()

我无法弄清楚那台特定的计算机出了什么问题,因为同样的事情适用于其他Windows 7用户。

另外,我还尝试重新安装SQL Server CE Runtime 3.5 SP2,但没有成功。

要添加更多信息,请在指定位置成功创建数据库,但是我无法执行其他操作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...