SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had a DB that normally I access from my SharePoint (2010) custom feature by Entity Framework. The connection string is stored in the web.config.

If I do something like that from outside TimerJob:

using (DB db = new DB()) { }

I get a working instance, if I do the same thing from TimerJob I get exception. To avoid this I stored a connection string into my "Configuration List" so that my code now is:

string cs = //GET STRING FROM LIST
using (DB db = new DB(cs)) { }

but this generates me an exception.

Where is the problem?

I tried with these connection string: metadata=res:///NewDB.csdl|res:///NewDB.ssdl|res://*/NewDB.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.;Initial Catalog=CNH_MW;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework'


metadata=res:///NewDB.csdl|res:///NewDB.ssdl|res://*/NewDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=CNH_MW;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"

without any success..

Exception: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid
Stacktrace:    at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) 

at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) at CNH.WorkFlowManufacturing.CNH_MW..ctor() at CNH.WorkFlowManufacturing.DBHandler.get_GetCNH_MW() at CNH.WorkFlowManufacturing.JobImportazione.ImportaFile(SPFile file, SqlConnection& conn, Int32 PK_LOG) at CNH.WorkFlowManufacturing.JobImportazione.Execute(Guid targetInstanceId)

Any suggestion? Thank you very much!

share|improve this question
Can you please add the message/stack from the exception you are experiencing? – SPArchaeologist Mar 4 '13 at 14:24
Added right now – Ziba Leah Mar 4 '13 at 14:25
up vote 2 down vote accepted

The OWSTIMER doesn't run in a web context and does not have immediate access to your web application web.config files.

You can use something like this tutorial to read web.config values from your web apps:

You can also create an app.config file right next to the OWSTIMER.exe file (would be owstimer.exe.config).

And lastly, you could store that data in a different fashion (i.e. Farm Properties in the Object Model).

EDIT: Here is an example of creating the OWSTIMER config file:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.