0
var serviceUrl = "/_vti_bin/listdata.svc";
var context = new listservice.TestingEnvironmentDataContext(new Uri(serviceUrl));
context.Credentials = System.Net.CredentialCache.DefaultCredentials;

var products = from product in context.Test
               where product.Title == "1"
               select product;

foreach (var product in products)
{
    Label1.Text = products.ToString();
}

On the above code I am getting "dataservicequeryexception is unhandled by usercode" error at the foreach loop. Does anybody know why?

  • ambiguity? product is a variable for the foreach loop and inside the lync query. Also, if you are trying to find one value, you can use product.FirstOrDefault() – Mike Jul 29 '14 at 20:40
  • Now i noticed..for the above code the error i am getting is "system.net.credentialcache.defaultcredentials 401 unauthorized." how to fix it. – user4044 Jul 31 '14 at 14:39
  • the user that you are running this code doesn't have the required permissions in order to grab the items. – Mike Jul 31 '14 at 14:40
  • The logged in user is the person who created the web application and site collection. why would he not have permissions?? anyway is there any another code where i can give credentials of sharepoint farm account. – user4044 Jul 31 '14 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.