开发者

Problem accessing EF resources from windows service

开发者 https://www.devze.com 2023-03-03 04:43 出处:网络
I have a WCF service which uses Entity Frameworks to connect to a database, all hosted in a Windows Service.The problem is that when the first message is handled to cause a database access, an excepti

I have a WCF service which uses Entity Frameworks to connect to a database, all hosted in a Windows Service. The problem is that when the first message is handled to cause a database access, an exception is thrown: "Unable to resolve assembly 'MyService.exe'". Basically, when running as a windows service EF can't locate the embedded resources.

I've checked for the presence of the 3 resources, csdl, ssdl, msl using .Net Reflector in the static exe and they're there. I'm using this connection string

    metadata=res:// MyService.exe/MyModel.csdl|
             res:// MyService.exe/MyModel.ssdl| 
             res://MyService.exe/MyModel.msl; provider=...".  

I added code to the Windows Service to enumerate the embedded resources in the OnStart method when the service is started (using GetExecutingAssembly(). GetManifestResourceNames()), and it s开发者_开发技巧hows nothing there. [of course, the win svc is installed/run with installutil + net start]. When I run a nearly identical project, linking to all the same sources including the app.config, as an interactive console app (different Main() of course), everything works fine, including the enumeration of the resources (all 3 edmx mapping files are there). The Win Svc is running under Local System.

Has anyone else had difficulties using EF in a windows service? Any ideas about whats going wrong or how to diagnose/fix it?


Try replacing "MyService.exe" with "*" like this:

<add name="MyEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=DatabaseName;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
0

精彩评论

暂无评论...
验证码 换一张
取 消