【发布时间】:2016-06-28 11:32:28
【问题描述】:
我有一个使用实体框架(DB 优先方法)的 WPF 程序。它在我的开发笔记本电脑上运行良好,但在其他计算机上一开始就崩溃了,这显然是因为它无法连接到数据库。
但是关于问题的根源,我在网上阅读了很多东西,虽然我没有任何确定的答案,但似乎它与连接字符串和app.config一般有关。
我在我的开发笔记本电脑上使用 Microsoft SQL Server Management Studio,并在测试单元上安装了 Microsoft SQL Server。
整个场景是我想发布我的应用程序,任何用户都可以轻松下载和安装它。
这是我的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.2" />
</startup>
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="AssetManagementDBEntities"
connectionString="metadata=res://*/Entity.AssetManagementDBModel.csdl|res://*/Entity.AssetManagementDBModel.ssdl|res://*/Entity.AssetManagementDBModel.msl;provider=System.Data.SqlClient;provider connection string="initial catalog=AssetManagementDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient"/>
</connectionStrings>
</configuration>
另外我不得不说,我找不到csdl、ssdl 和msl 必须在其中的.dll 文件!
.edmx 文件的“构建操作”设置为EntityDeploy
【问题讨论】:
-
你能在 appconfig 中显示你的连接字符串吗?
-
我在您的连接字符串中看不到的是
data source=SQLSERVERLOCATION;它应该在 "ed 部分内。至于值,它取决于 sql server 的安装,使用 Management Studio 在您登录server name文本框时显示的任何内容,您的计算机上的值可能会有所不同。 -
但它在我的笔记本电脑上运行良好。而在其他计算机上可能会有所不同,不是吗?
-
也许您使用的本地数据库存在于您的笔记本电脑上,但不存在于其他计算机上。
-
是的,我使用本地数据库。如果文件不存在,我希望程序在计算机上创建文件
标签: c# sql-server wpf entity-framework-6