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'
OR
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!