Unable to start debugging on the Web server. The Web Server Could Not Find the Requested Resource.

Background

I was given a Windows 7 machine.  It has VS2010 and VS2013.  It also has .NET 4.5.1 installed.

Problem

My web project uses a local IIS and it fails to start in debug when the application pool uses Classic with .NET 4.0.  It debugs in Integrated mode.

Solution

I followed an article online (probably from stackoverflow)

“open IIS7 (run > inetmgr) and go to the Feature view. Open the ISAPI and CGI Restrictions section and check if your .Net version has the correct restriction (for example, if you’re working with 4.0 is should be on “Allowed”)”

image

Advertisements

Entity Framework Code First ProviderIncompatibleException

Background:

I am trying out Visual Studio 2013 Entity Framework 6 Code First to create a new database.

So I coded the model (i.e. entity classes) and the context (i.e. DbContext).

Problem:

When I tried “Enable-Migrations” in package manager console, I got the following error:

PM> Enable-Migrations

Checking if the context targets an existing database…

System.Data.Entity.Core.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. —> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. —> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

Solution:

1.  Find out the actual connection string being used by writing out the connecting string in your Context class’s constructor.  Of course you will need to run/debug the code in order to see the connections string in the debug output window.

public class MyContext : DbContext
{
    public MyContext()
    {
        // Find out the connection string being used
        Debug.Write(Database.Connection.ConnectionString);
    }
    public DbSet<MyEntity> MyEntities { get; set; }
}

 

2. Add the connection string to the Context class

public class MyContext : DbContext
 {
     public MyContext()
     : base(@"Data Source=(localdb)\v11.0;Initial Catalog=NameSpaceXXXX.MyContext;Integrated Security=True")
     {
         // Find out the connection string being used
         Debug.Write(Database.Connection.ConnectionString);
     }
     public DbSet<MyEntity> MyEntities { get; set; }
 }

 

Discussion:

With the default code first approach, you won’t find a connection string in web.config.

Things are done by convention and there is no need specify a connection string.  However, since it is not working, I am using the work around.

I suppose specifying the connection string explicitly in the web.config should also work.

Reference:

http://msdn.microsoft.com/en-us/data/jj193542#

http://odetocode.com/blogs/scott/archive/2012/08/15/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx