c# - WPF application with Entity Framework, proper settings for app.config -
i have wpf program uses entity framework (db first approach). works fine on development laptop, crashes right @ beginning on other computers , it's because how can not connect db.
but root of problem, read many things online, , although don't have answer seems has connection string , app.config
in general.
i use microsoft sql server management studio on development laptop , i've installed microsoft sql server on test unit.
the whole scenario want publish application , user can download , install easily.
here 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>
also have say, couldn't find .dll
file csdl
, ssdl
, msl
must in that!
the "build action" of .edmx
file set entitydeploy
finally found solution self:
as explained here, it's not possible db-first approach, because tries initialize model each time, , therefore needs db exist. copied classes , files created based on db , use them code-first approach (the above link explained well). note should remove connectionstring
totally, because it's explained in link, db context takes care of that.
note have have sqlexpress or localdb on machine (if have installed visual studio 2010 or 2012 1 of them installed).
now when program runs first time, creates db file in c:\users\[your_user_name]
(there should 2 files, main db file , log
file).
leave comment if have questions details
Comments
Post a Comment