[英]WCF & Entity Framework & SQL Server - “The underlying provider failed on Open”
[英]Entity Framework & SQL Server CE - Underlying Provider Failed On Open
我正在构建供组织内部使用的应用程序。 它连接到存储在我们的数据服务器上的SQL Server CE数据库。 该程序在我的机器上可以正常工作,但是每当我尝试将其部署到另一个用户时,都会出现以下错误:
初始化数据库时发生异常。 有关详细信息,请参见InnerException。
在System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action动作)
在System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
在System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c)
在System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1.PerformAction(TInput input)
1动作)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(TypeEntityType)
在System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
1.GetEnumerator()
at System.Data.Entity.Internal.Linq.InternalSet
在System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator()
在System.Data.Entity.QueryableExtensions.Load(IQueryable源)
在RunBKSales.Edit_Menu.Window_Loaded(Object sender,RoutedEventArgs e)基础提供程序在打开时失败。
最后一行应该是InnerException。 这是引发错误的代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
dbContext.Combos.Load();
dbContext.Products.Load();
dbContext.Stores.Load();
comboDataGrid.DataContext = dbContext.Combos.Local;
productDataGrid.DataContext = dbContext.Products.ToList();
storeDataGrid.DataContext = dbContext.Stores.ToList();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message + " " + ex.StackTrace);
System.IO.File.AppendAllText(LOG_FILE, String.Format("{0} \t {1} {2} {3}", DateTime.Now.ToShortDateString(), ex.Message, ex.StackTrace, ex.InnerException.Message) + System.Environment.NewLine);
}
}
连接字符串的“数据源”是.sdf
数据库文件的UNC路径。
App.config中
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0"
type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<connectionStrings>
<add name="BKSalesModel"
connectionString="Data Source=\\FULL\UNC\PATH\db.sdf;Persist Security Info=False;"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
再次,它在我的机器上可以正常工作,因此我在调试它时遇到了麻烦。 任何意见,将不胜感激。
在“内部异常”的内部异常中查找根本原因错误消息!
您不能跨LAN使用SQL Compact,它是一个单计算机数据库(尽管您可以在同一台计算机上让多个进程使用位于本地磁盘上的同一数据库)
若要通过LAN共享数据,应使用SQL Server Express
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.