Gratziani V.
Gratziani V.

Reputation: 127

Accessing database from a Windows Service

I have this ASP.NET app, in which I use Entity Framework to connect to the DB. Inside this app I have a class which provides different operations on the DB (add, remove etc). Everything works dandy. Now I needed to create a Windows Service which once a week updates the DB with info gathered from a repository. I thought that I could add my ASP.NET dll as a reference to my windows service, so that I could use the operations I defined there. But I get the following error:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

I read in some other thread that I should copy the connect string to the app.config, but I don't have any app.config file in my windows service project. How can I use the EDM operations I defined in the class in both the ASP app and the windows service?

Upvotes: 2

Views: 3666

Answers (1)

bhuvin
bhuvin

Reputation: 1402

Dude u need to create an app.config in that case . Copy the connection string in the web app to the app.config with the same name. See when the windows service is running and the EF tries to create data context it doesnt find any and hence it shows the error. So u should add one app.config file and add the connectionstring to it appropriately.

Upvotes: 4

Related Questions