0

Okay my project has a separate class library that has all the EnitityFramework version 6.1.3 code and settings.

I can not get this to connect to anything other than my local sql db

I can connect to my sql box 192.111.111.111\sql_box with SQL manager, SQL server object explorer and LINQpad. so it is there and connection string is correct.

I think I am now meant to be doing code based configuration

so my App.cong looks like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <entityFramework codeConfigurationType="MyProject.CodeConfig, MyProject">
  </entityFramework>

</configuration>

and I have also create and class that derives from DbConfiguation

  public class CodeConfig : DbConfiguration
    {
        public CodeConfig()
        {
            this.SetProviderServices("System.Data.SqlClient",
                System.Data.Entity.SqlServer.SqlProviderServices.Instance);
        }
    }

but where do I put 192.111.111.111\sql_box

every time I run Update-Database in the package manager I get

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)

2 Answers 2

1

In the web.config or in the app.config.

<configuration>
    <connectionStrings>
       <add name="YOURDBCONTEXTNAME" connectionString="data source=SERVER;initial catalog=DATABASE;Integrated Security=false;persist security info=True;user id=USER;password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

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

Comments

0

Your connection string needs to be in the web/app config file in the startup project.

The connection string in the class library (assuming it is not the startup project) is used when making model changes, migrations, etc.

1 Comment

im going to have to be dumb here, so sorry about this. But I have put the connectionStrings in the Web.Config that is the MVC project that is the start up. The MVC project has no EntityFramework in it so when I point the package manager at the MVC project and enter Update_database I get told "The EntityFramework package is not installed on project" and when I install it, it seems to want all migration stuff to be in the MVC project

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.