Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework works on Local Server but not Remote

Ok so I have a website that uses ASP.net mvc, the problem I am having is with Entity Framework. I added all the references and got it to run on my local machine but when I publish it I get the following error.

System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I have double checked my references and I have EntityFramework.SqlServer and System.Data both added into my project. The connection string I use to connect to the data base and declare the service provide is below.

<connectionStrings>
<add name="[dataConnection]" connectionString="Data Source=[ip of host machine];Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>

Name we just have the name of the data base, this is also used in my web.debug.config

<connectionStrings>
<add name="[dataconnection]"
  connectionString="Data Source=.;Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;"
  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

I am pretty new to this entire thing and was just handed someone elses code so I am trying to learn on the flow. This is my first encounter with this so any direction would be appreciated.

like image 966
Ken Avatar asked Dec 04 '12 20:12

Ken


1 Answers

I had the same problem in my integration test assembly (i'm using ms visual studio unit testing framework for this) and i've solved it by adding EF assemblies to deployment items in .testsettings file.

  1. I've installed EF 6 alpha using Package Manager Console using: Install-Package EntityFramework -Pre

Here is my app.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    </configuration>

My connection string (i'm setting it in code): server=.\SIN;initial catalog=IntegrationTests;User ID=user;Password=pass;MultipleActiveResultSets=true;

  1. I've looked at the EF assembly reference properties to see if they are set to "Copy Local" = True. And finally i've checked out TestResults/../Out folder and found that there is no EntityFramework.SqlServer assembly there (SqlProviderServices class resides in it).

  2. So i've just added both EF 6 assemblies to my deployment items and now everything is ok deployment items

You can try to copy EntityFramework.SqlServer assembly to your web server directory to see if it works.

Maybe this link can be helpful

P.S:

Make sure you don't have a reference to System.Data.Entity, because you'll be using one from GAC. EF 6 Alpha assemblies is not installed in GAC when you install them with Nuget. Target framework should be .NET 4.5.

Sorry for my bad english.

like image 138
Vasiliy Yorkin Avatar answered Sep 20 '22 09:09

Vasiliy Yorkin