Saturday, 20 February 2016

Add Connection String in Share point TimerJob from web.config file

 add connection string in SPTIMERJOB  




Step -1

add .dll references

Microsoft.SharePoint.Client.ServerRuntime
Path
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.ServerRuntime.dll
System.Configuration
path
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Configuration.dll
System.Web
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll

Step -2    

add namespace

using System.Web.Configuration;
using System.Configuration;




SPWebApplication webApplication = this.Parent as SPWebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);
string conStr = config.ConnectionStrings.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);

No comments:

Post a Comment