简体   繁体   English

实体框架和SQL Server CE-基础提供程序在打开时失败

[英]Entity Framework & SQL Server CE - Underlying Provider Failed On Open

I am building an application for internal use by my organization. 我正在构建供组织内部使用的应用程序。 It connects to a SQL Server CE database stored on our data server. 它连接到存储在我们的数据服务器上的SQL Server CE数据库。 The program works fine on my machine, but whenever I try to deploy it to another user, I received the following error: 该程序在我的机器上可以正常工作,但是每当我尝试将其部署到另一个用户时,都会出现以下错误:

An exception occurred while initializing the database. 初始化数据库时发生异常。 See the InnerException for details. 有关详细信息,请参见InnerException。
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) 在System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action动作)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() 在System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c) 在System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
在System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1 action)
1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1动作)

at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(TypeEntityType)
at System.Data.Entity.Internal.Linq.InternalSet 1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
在System.Data.Entity.Internal.Linq.InternalSet 1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.GetEnumerator()
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.GetEnumerator()

at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator() 在System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator()
at System.Data.Entity.QueryableExtensions.Load(IQueryable source) 在System.Data.Entity.QueryableExtensions.Load(IQueryable源)
at RunBKSales.Edit_Menu.Window_Loaded(Object sender, RoutedEventArgs e) 在RunBKSales.Edit_Menu.Window_Loaded(Object sender,RoutedEventArgs e)

The underlying provider failed on Open. 基础提供程序在打开时失败。

The last line should be the InnerException. 最后一行应该是InnerException。 This is the code that throws the error: 这是引发错误的代码:

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);
    }
}

The "Data Source" of the connection string is an UNC path to the .sdf database file. 连接字符串的“数据源”是.sdf数据库文件的UNC路径。

App.config 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>

Again, it works fines on my machine, so I am struggling with debugging it. 再次,它在我的机器上可以正常工作,因此我在调试它时遇到了麻烦。 Any advice would be appreciated. 任何意见,将不胜感激。

Look at the Inner Exception of the "inner Exception" for the root cause error message! 在“内部异常”的内部异常中查找根本原因错误消息!

You cannot use SQL Compact across a LAN, it is a single machine database (you can have several processes on the same machine use the same database located on a local disk, though) 您不能跨LAN使用SQL Compact,它是一个单计算机数据库(尽管您可以在同一台计算机上让多个进程使用位于本地磁盘上的同一数据库)

For sharing data across a LAN you should use SQL Server Express 若要通过LAN共享数据,应使用SQL Server Express

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF和实体框架和SQL Server - “底层提供程序在Open上失败” - WCF & Entity Framework & SQL Server - “The underlying provider failed on Open” 基础提供程序无法打开-WPF和实体框架 - The underlying provider failed to open - WPF and Entity FrameWork 实体框架底层提供程序在打开时失败 - Entity Framework The underlying provider failed on Open 实体框架异常“底层提供程序打开失败” - Entity Framework Exception “The underlying provider failed on Open” 基础提供程序在实体框架中打开时失败 - The underlying provider failed on Open in entity framework connection 实体Framewok-基础提供程序在打开时失败-SQL - Entity Framewok - The underlying provider failed on Open - SQL NServiceBus和实体框架导致异常-基础提供程序在打开时失败 - NServiceBus and Entity Framework causes exception - The underlying provider failed on Open 在实体框架上下文中使用单例模式-基础提供程序在打开时失败 - Using singleton pattern with Entity Framework context - The underlying provider failed on open SQLite&Entity Framework 6“基础数据提供程序无法打开” - SQLite & Entity Framework 6 “The underlying data provider failed to open” 实体框架:基础提供程序在打开时失败-通过WCF服务 - Entity Framework: The underlying provider failed on Open - through WCF service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM