0

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.

14
  • Can you please provide connection string? Maybe is problem with your connection string in Web project. By the way, when you start web project it will pull connection string from Web.config not from App.config. Commented Dec 1, 2016 at 19:28
  • @kat1330 Even being in separate projects it will get the connection string from the Web.config in the other project? I don't think it's the connection string because the error it's because it tries to access App_data. Commented Dec 1, 2016 at 19:32
  • What is a CrmDbInitializer? Commented Dec 1, 2016 at 19:41
  • @KevinAmorim Who tries to access to App_data? I am guessing context will try to access App_data if you specify in connection string. Maybe I am wrong. Commented Dec 1, 2016 at 19:48
  • From the error, I am pretty sure its somewhere in the connection string portion of the Connection String. Commented Dec 1, 2016 at 20:15

1 Answer 1

1

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.

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

Comments

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.