0

I need to retrieve the items of BCS based list.
I am using the server side object model on SP2013 and I am getting this error:

An error occurred while enumerating through a collection: The shim execution failed unexpectedly – Could not load file or assembly ‘System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)

I am running this code from a console application:

using (SPSite site = new SPSite("http://mysiteUrl")) { var context = SPServiceContext.GetContext(site); using (var scope = new SPServiceContextScope(context)) { SPWeb web = site.OpenWeb(); using (web) { SPList myList = web.Lists["BCS List"]; var items = (from SPListItem item in myList.Items where Convert.ToString(item["MyField"]) == "myValue" select item).ToList(); } } } 

The problem is on the .Items attribute.

2 Answers 2

0

I solved running the console application with Administrator privileges.

0

As an alternative to your solution based on running the program under admin account, you can give a try to using impersonation in SP code. Hope these links would be useful for you: https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx http://blogs.technet.com/b/sharepointdevelopersupport/archive/2013/03/13/using-spsite-and-spweb-objects-with-runwithelevatedprivileges-don-t-cross-the-borders.aspx https://msdn.microsoft.com/en-us/library/ms436101

1
  • I tried also to use it, but it did not help. I think that the problem was to load some DDLs that is why run shell as admin solved the problem. Commented Oct 8, 2015 at 18:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.