首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体框架& Server -基础提供程序在打开时失败

问实体框架& Server -基础提供程序在打开时失败
EN

Stack Overflow用户
提问于 2017-04-11 19:49:21
回答 1查看 403关注 0票数 0

我正在构建一个应用程序供我的组织内部使用。它连接到存储在数据服务器上的server数据库。该程序在我的机器上运行良好,但是每当我试图将它部署到其他用户时,我就会收到以下错误:

初始化数据库时发生异常。有关细节,请参阅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行动) 在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 在System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.1.GetEnumerator() 在System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator() (在System.Data.Entity.QueryableExtensions.Load(IQueryable源) 在RunBKSales.Edit_Menu.Window_Loaded(对象发送方,RoutedEventArgs e) 基础提供程序在打开时失败。

最后一行应该是InnerException。这是抛出错误的代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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>

再次,它在我的机器上工作罚款,所以我正在努力调试它。如有任何建议,将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-04-12 06:24:02

查看内部异常的“内部异常”的根本原因错误消息!

不能在局域网中使用,它是一个单机数据库(但是,同一台机器上可以有多个进程使用位于本地磁盘上的同一数据库)

要在局域网之间共享数据,应使用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43354991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档