SharePoint web application or site will run with the help of process 'W3WP.EXE'.
SharePoint timer job is running in different process named 'OWSTIMER.EXE'.
So, the application configuration file is associated with the W3WP.EXE, so there is no way to access the web.config file in the owstimer.exe process at all. The context is completely different and out of domain. So, we need to call or access the web.config file explicitly in timer job.
So add below code in Execute() method to access ConnectionString in Timer JOB.
SPWebApplication webApplication = this.Parent as SPWebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);
_ConnString = config.ConnectionStrings.ConnectionStrings["ConnectionName"].ConnectionString.ToString();
No comments:
Post a Comment