Reputation: 535
I've been trying to connect my ASP.NET MVC application to a SQL database without success.
I have in my DAL project, in App.config:
<connectionString>
<add name="CrmContext" connectionString="..." providerName="..." />
</connectionString>
And in my WebUI project, in the Web.config file I have:
<connectionString>
<add name="CrmContext" connectionString="..." providerName="..." />
</connectionString>
My context in the DAL project is declared like this:
public CrmContext() {
Database.SetInitializer(new CrmDbInitializer());
}
The initial seeding of the database works fine, but then when a Controller tries to access the database it gives me the error:
SQL Network interfaces, Error: 26 - Error locating Server
Apparently it tries to create/access the database in App_data folder. I've tried many things for hours and nothing works...
I'm using EntityFramework and Code-First approach.
Upvotes: 0
Views: 702
Reputation: 535
I fixed the problem.
I kept the Connection String in the Web.config, no problems with that.
The problem was with the Authentication. I was missing
<membership defaultProvider="CrmContext"
<providers>
<clear />
<add name="CrmContext" connectionStringName="DefaultConnection" />
</providers>
</membership>
Also, I had to remove from my Web.config:
<roleManager.... />
And everything started working fine, even Authentication. My "DefaultConnection" connection string points to my database, of course.
I hope it helps someone with the same problem.
Upvotes: 1