Hi,
I want to create a Timer job that runs once daily to fetch legacy data from an external List( another SQL server dB) and update a local sharepoint list.
I've created an external list which gets data from SQL server DB. I'm using the SP API to connect to external list and get data. When I run the code inside a visual web part it runs fine. But when I place the code inside Execute() method of SPJobDefinition
(a sharepoint Timer job) it fails with Microsoft.BusinessData.Infrastructure.BdcException: The shim execution failed unexpectedly - Proxy creation failed. Default context not found.. ---> Microsoft.Office.SecureStoreService.Server.SecureStoreServiceException:
Proxy creation failed. Default context not found.
I have created a secure store and given credential permission to an account that has access to the external SQL server. I've also given BCS permissions for that external list to this account.
Here is the code:
publicoverridevoid
Execute(Guid
dbID)
{
try
{
string
camlQueryText = "don't worrry about
the query. I know it works fine";
SPWebApplication
webApplication = this.ParentasSPWebApplication;
SPContentDatabase
contentDb = webApplication.ContentDatabases[dbID];
SPList myExtList
= contentDb.Sites[0].RootWeb.Lists["My
External List"];
SPQuery
querySearch = newSPQuery();
querySearch.Query = camlQueryText;querySearch.ViewFields =
"<FieldRef Name='vchrDescModel' />";
querySearch.ViewFieldsOnly =
true;
SPListItemCollection
collListItems = myExtList.GetItems(querySearch);
foreach
(SPListItem
item in
collListItems)
{
// check to see if the model exists in DMC List.
If it doesn't then add it.
string str = item[
"vchrDescModel"].ToString(); // then I update the local sharepoint list with this data.
}
}
catch
(Exception
ex)
{
System.Diagnostics.
EventLog.WriteEntry("Execute",
ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
}
}
-------------------
The above code works fine when run inside a visual web part. The exception I get is this:
Microsoft.BusinessData.Infrastructure.BdcException: The shim execution failed unexpectedly - Proxy creation failed. Default context not found.. ---> Microsoft.Office.SecureStoreService.Server.SecureStoreServiceException: Proxy creation failed. Default
context not found.
at Microsoft.Office.SecureStoreService.Server.SecureStoreProvider.get_Proxy()
at Microsoft.Office.SecureStoreService.Server.SecureStoreProvider.GetRestrictedCredentials(String appId)
at Microsoft.SharePoint.BusinessData.Infrastructure.WindowsAuthenticator.ExecuteAfterLogonUser(Object[] args, ISecureStoreProvider ssoProvider, String ssoApplicationId, Boolean useSensitiveSsoCreds)
at Microsoft.SharePoint.BusinessData.Infrastructure.WindowsAuthenticator.ExecuteAfterLogonUser(Object[] args, ISecureStoreProvider ssoProvider, String ssoApplicationId)
at Microsoft.SharePoint.BusinessData.SystemSpecific.Db.DbConnectionManager.GetConnection()
at Microsoft.SharePoint.BusinessData.SystemSpecific.Db.DbSystemUtility.ExecuteStatic(IMethodInstance methodInstance, ILobSystemInstance lobSystemInstance, Object[] args, IExecutionContext context)
at Microsoft.SharePoint.BusinessData.Runtime.DataClassRuntime.ExecuteInternalWithAuthNFailureRetry(ISystemUtility systemUtility, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, ILobSystemInstance lobSystemInstance, ILobSystem
lobSystem, IParameterCollection nonReturnParameters, Object[] overrideArgs)
at Microsoft.SharePoint.BusinessData.Runtime.DataClassRuntime.ExecuteInternal(IDataClass thisDataClass, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, IParameterCollection
nonReturnParameters, Object[]& overrideArgs)
--- End of inner exception stack trace ---
at Microsoft.SharePoint.BusinessData.Runtime.DataClassRuntime.ExecuteInternal(IDataClass thisDataClass, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, IParameterCollection
nonReturnParameters, Object[]& overrideArgs)
at Microsoft.SharePoint.BusinessData.Runtime.EntityRuntime.ExecuteInternal(IDataClass thisDataClass, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, IParameterCollection
nonReturnParameters, Object[]& overrideArgs, IFilterCollection filters)
at Microsoft.SharePoint.BusinessData.Runtime.EntityRuntime.ExecuteFiltered(IEntity this, IFilterCollection filterCollection, IMethodInstance methodInstanceToExecute, ILobSystemInstance lobSystemInstance)
at Microsoft.SharePoint.BusinessData.Runtime.EntityRuntime.<FindFiltered>b__3(IEntity e, IMethodInstance mi, IFilterCollection fc, ILobSystemInstance lsi)
at Microsoft.SharePoint.BusinessData.Runtime.EntityInstanceEnumeratorFactory.CreateEntityInstanceEnumerator(IEntity entity, IMethodInstance methodInstance, IFilterCollection filters, ILobSystemInstance lobSystemInstance, ExecutionCallBack executionCallBack)
at Microsoft.SharePoint.BusinessData.MetadataModel.Static.Entity.FindFiltered(IFilterCollection filterCollection, String finderName, ILobSystemInstance lobSystemInstance)
at Microsoft.SharePoint.SPListDataSource.GetEntityInstanceEnumerator(XmlNode xnMethodAndFilters)
at Microsoft.SharePoint.SPListDataSource.GetFilteredEntityInstancesInternal(XmlDocument xdQueryView, Boolean fFormatDates, Boolean fUTCToLocal, String firstRowId, Boolean fBackwardsPaging, String& bdcidFirstRow, String& bdcidNextPageRow,
List`1& lstColumnNames, Dictionary`2& dictColumnsUsed, List`1& mapRowOrdering, List`1& lstEntityData)
at Microsoft.SharePoint.SPListDataSource.GetFilteredEntityInstances(XmlDocument xdQueryView, Boolean fFormatDates, Boolean fUTCToLocal, String firstRowId, Boolean fBackwardsPaging, String& bdcidFirstRow, String& bdcidNextPageRow, List`1&
lstColumnNames, Dictionary`2& dictColumnsUsed, List`1& mapRowOrdering, List`1& lstEntityData)
at Microsoft.SharePoint.SPListItemCollection.EnsureEntityDataViewAndOrdering(String& bdcidFirstRow, String& bdcidNextPageFirstRow)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.get_Count()
at Microsoft.SharePoint.SPEntityInstanceEnumerator.System.Collections.IEnumerator.MoveNext()
at Honda.UK.SharePoint.DMC.TestArea.SimpleTimerTask.Execute(Guid dbID)
Can you please please help!
King regards,
Zohaib