Sunday, February 03, 2008

Common Reason ADO.NET Data Services Don't Work With ADO.NET Entity Framework and Linq to SQL

I'm playing around a little bit with ADO.NET Data Services today, and had some trouble getting ADO.NET Entity Framework to work.  My ATOM document was returning an empty result set.  So, when I went to my page, I'd get results that looked like this:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<service xml:base="http://localhost:60618/TimeTracker/Services/TimeTrackerDataService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">
    <workspace>
        <atom:title>Default</atom:title>
    </workspace>
</service>

I double checked that I was allowing the appropriate read rights to the resources, as I had this line in my service:

config.SetResourceContainerAccessRule("*", ResourceContainerRights.AllRead);

As it turns out, this is caused by the fact that the designer file for the edmx or dbml file has an incorrect connection string or a missing connection string from the default constructor.  If you go through the ADO.NET Data Services wizard, and don't choose "Save entity connection settings..." checkbox, you'll get this error.

image

If you're using Linq to SQL or ADO.NET Entity Framework, your resolve the same way.  Just open up the designer files for the edmx or dbml files, and change the default constructor so that it is populating the connection string correctly.

0 comments: