# Monday, May 07, 2012
« I just passed the 175000 recognition poi... | Main | I just registered for Community Day 2012... »

Today I was trying to run a sample application for VS11 Beta that I found online: Download Hands-on Lab Source Files. However when trying to run the pages I encountered the following error:

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)

Looking into the inner exception:

ANetworkRelatedErrorOccured

gave me the following:

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).

Ouch!

Well, what I could’ve done is trying to fiddle around with settings of SQL Server, trying to get it right and working. However I noticed that Entity Framework was being used and in the code I found this little piece:

public class ProductsContext : DbContext
{
    public ProductsContext() : base("WebFormsLab-Products")
    {
    }

    public DbSet<Category> Categories { get; set; }
        
    public DbSet<Product> Products { get; set; }
        
    public DbSet<Customer> Customers { get; set; }
}

Inherits from DbContext? Aha, that’s interesting. Now, let me see if we can get SQL Server Compact into play. Well, we can. There’s a nice Nuget package available:

PM> Install-Package EntityFramework.SqlServerCompact

This will update the web.config as well as besides downloading the package. Now running the same page again it shows the information nicely instead of giving that nasty error. Also it generated a new database file in the App_Data subfolder:

sdfcreated

Super!

Conclusion: SQL Server Compact to the rescue together with Entity Framework Code First. It’s easy to integrate via Nuget and it simply works (disclaimer: on this machine).

Grz, Kris.