Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
A network-related or instance-specific error occurred while establishing a connection to SQL Server

The main page loads fine, but the error occurs when I try to goto Account/Register or Account/Login.

The error occurs on this line in SimpleMembershipInitializer constructor in file Filters/InitializeSimpleMembershipAttribute.cs

if (!context.Database.Exists())

Now, if I set my web.config to

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />
</entityFramework>

it works locally only but I'm assuming it's using a local database. Right now my entity framework in the web.config looks like

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

I have another application where I am using the same hosting service and free database (appharbor and SQL Server Yocto) and it works just fine. I recently setup a new application and database and it doesn't work. I can connect to the database fine in SQL server and expanding the DataConnections -> MyContextName in visual studio 2012, so I know the connection string is not the problem.

I'm wondering if there is a problem on the server the database is hosted on and I don't have access to that.

I'm all out of ideas on how to fix this problem. Thanks.

share|improve this question
    
Is the new database on the same SQL server instance? –  Ryan yesterday
add comment

1 Answer

The problem probably is that the connection string name hasn't been configured properly and/or doesn't follow the entity framework conventions (which differs a bit between Entity framework versions). If you can connect to the database from your own machine or from the SQL server admin page the problem is unlikely to be related to the database/database server itself.

Take a look at this discussion where another user experienced a similar issue. You might just need to set the right connection string name for the entity framework database context. Also make sure you have migrations set up to create the database.

This may explain why it's working locally with the local db connection factory. I suspect that a database is created in your local SQL server, and it can do so unrestricted. On AppHarbor you need to use the database and connection string provided since you can't create databases yourself. You can confirm whether that's the case by connecting to your local database server and listing the available databases.

I can also recommend using this sample application and the associated blog posts about running migrations and configuring entity framework (4.3) on AppHarbor.

share|improve this answer
add comment

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.