Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I know this is a common problem and there are lots of suggestions on the internet, but non of them helped me to sort this issue out.

I have created my data context class by using SPMetal.exe tool.

I have created a console application with the configuration below

CPU: Any CPU Framework: .net 3.5

I tried to test whether my datacontext is working fine or now via the lines below,

  IMG.CustomerPortal.Data.Context.IMGContextDataContext con = new IMG.CustomerPortal.Data.Context.IMGContextDataContext("http://server/site_name/");
        EntityList<TicketItem> lst = con.GetList<TicketItem>("ListName");

        Console.WriteLine(lst.First().ClosedDate);
        Console.ReadKey();

it throws an error below;

The Web application at http://server/site_name/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

However, in same project, I am able to access to the data via client object model by using the code below;

 string siteUrl = "http://server/site_name/";

        ClientContext clientContext = new ClientContext(siteUrl);
        Web oWebsite = clientContext.Web;
        ListCollection collList = oWebsite.Lists;

        clientContext.Load(collList);

        clientContext.ExecuteQuery();

        foreach (var oList in collList)
        {
            Console.WriteLine("Title: {0} Created: {1}", oList.Title, oList.Created.ToString());
        }
        Console.ReadKey();

Is there anything I am doing wrong here? it does not seem to be related to framework version or architecture.

is there anything missing, or any idea why it throws this?

Thanks

share|improve this question

1 Answer 1

It looks like you should open console application project properties, go to the Build tab and select x64 in platform target dropdown list.

Also you should check that you runs your console application on the mashine that hosts Server/Site_Name.

share|improve this answer
    
nope.. I tried it already and gave another try after your reply.. still same, I am afraid.. –  AnarchistGeek Apr 2 '12 at 14:19
    
it is a stupid question... but are you sure that you runs your application on the pc that hosts the server/site_name ? –  Alexander Apr 2 '12 at 14:25
    
do I need to though? –  AnarchistGeek Apr 2 '12 at 14:36
    
you are right, I moved it to server and it worked.. do I have to work on the same machine as the Sharepoint is running on to use linq? –  AnarchistGeek Apr 2 '12 at 14:43
3  
No that's not bad, because you can use the REST API instead which works a lot better that the buggy LINQ provider. Add a web reference to server/site_name/_vti_bin/listdata.svc –  Per Jakobsen Apr 2 '12 at 15:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.