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

1
  • Is the new database on the same SQL server instance? Commented Jun 25, 2014 at 3:16

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much! the problem was the default connection string in accountmodel.cs was wrong!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.