4

I've been using a DAL Class Library for a ASP.NET MVC Site. The DAL Library has a repository for the queries.

It was all working fine until I tried to use the DAL library for a windows service, the service throws a exception when I reach the RARepository _repository = new RARepository(); or more specifically when the repository hits the private readonly RAEntities6 entities = new RAEntities6(); line.

The Exception thrown is

System.ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
   at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
   at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
   at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
   at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
   at RA.Models.RAEntities6..ctor() in C:\RADAL\Models\RAEntities.Designer.cs:line 54
   at RA.Repositories.RARepository..ctor() in C:\RADAL\Repositories\RARepository.cs:line 11
   at GDMService.ASU.OnElapsedTime(Object sender, ElapsedEventArgs e) in C:\RAPC7\GDMService\Service1.cs:line 78

I thought it may be a issue with the connection string using integrated security from a service (which runs as local sytem) so i tried first changing the connection string in app.config to have a user name and password for the sql server. The repositories still worked for the MVC Site, but not for the Service. After that i tried changing the connection string back to integrated security and made the service run as a user but the error was the same.

In the exception the line 78 is RARepository _repository = new RARepository();, the line 11 is private readonly RAEntities6 entities = new RAEntities6(); and the line 54 is in the entity framework designer constructor

public RAEntities6() : base("name=RAEntities6", "RAEntities6")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

Edit: I think what has happened is that when the service is running it no longer has permissions to open the config file (which contains the connection string), I have found now that when the service is running a load of .INI files can not be found but I'm not sure how to resolve this to give the service permissions, or where to put the config files so the service can access everything.

4
  • 2
    And where did you put the connection string for the service? Commented Jul 27, 2011 at 9:17
  • @Ladislav I tried putting it at first in the app.config of the service specifying the DAL namespace, and when that made no difference i updated the EF from the new connection string so that in the DAL library it was changed
    – Manatherin
    Commented Jul 27, 2011 at 9:22
  • Oh i changed it after in the DAL library so i could check (using the MVC) that the new connection string worked outside of the service
    – Manatherin
    Commented Jul 27, 2011 at 9:23
  • I am facing the same problem. Please help. Commented Jan 18, 2015 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.