12 Sep 2013

Modelling a Stored Procedure in EF: The selected stored procedure returns no columns

Trying to map a SQL Stored Procedure in Entity Framework in Visual Studio, I clicked "Update my Model from Database" on the EDMX view, and added the Stored Procedure. However, unlike other ones I had imported, when I looked in Model Browser, no Complex Type was created in the model to represent the result rows of the Stored Proc.

When I clicked on the Function Import for the sproc, The Return Type was set to none, so I tried to edit it. On the Edit Function Import screen, clicking Get Column Information resulted in: "The selected stored procedure returns no columns". This was not true!

Well, to cut a long story short, the fix was to include this line at the top of the Stored Proc SQL:

SET FMTONLY OFF;

After that, clicking Get Column Information worked, and I could create the new Complex Type with no problems.

11 Sep 2013

MVC 4 site in IIS virtual directory under a WordPress site returns 403 error

This was perplexing. I rolled out an MVC 4 subsite onto a virtual directory on a PHP (WordPress) site running on IIS 7.5. At first glance the MVC site was working okay, but then I realised that none of the routes were working, returning the following error:

403 - Forbidden: Access is denied.

You do not have permission to view this directory or page using the credentials that you supplied.


Viewing the pages from IE on the server provided a bit more information:

HTTP Error 403.18 - Forbidden

The specified request cannot be processed in the application pool that is configured for this resource on the Web server.

Module: IIS Web Core
Handler: PHP53_via_FastCGI

Well, there was the clue. The WordPress installation was handling the URL routing, even though my MVC site was running in a sub-application. I discovered WordPress was doing this by using an IIS web.config file with a rewrite rule in the root folder. So, the simple way to solve our problem was to override the rewrite rules, in the web.config of the subsite:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
        </rules>
    </rewrite>
</system.webServer>
If I helped you out today, you can buy me a beer below. Cheers!