Entity Framework works on Local Server but not Remote - asp.net

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.

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.
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;
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).
So i've just added both EF 6 assemblies to my deployment items and now everything is ok
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.

A question: which EF version?
Check your IIS pool .NET version... It should be the one that points to the .NET version of your published project... The assembly of EF should be in the .NET framework folder under Windows directory (AKA GAC)

Related

Razor Host Factory error

I get a MvcWebRazorHostFactory error trying to run my app, but it's not an MVC app at all. I have the following web packages installed via nuget:
Microsoft ASP.NET Razor
Microsoft ASP.NET Web API 2.1
Microsoft ASP.NET Web Pages
My app is angularjs front end using razor views (.cshtml). I don't understand why I keep getting this error.
An exception of type 'System.InvalidOperationException' occurred in System.Web.WebPages.Razor.dll but was not handled in user code
Additional information: Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
And here is the razor section in my web.config:
<system.web.webPages.razor>
<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.WebPages.WebPage">
<namespaces>
<add namespace="System.Web.Configuration" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
I resolved this issue by setting System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc Version to 5.2.0.0 and it worked, finally! Why 5.2.0.0? Same version as NuGet Microsoft ASP.NET project.
So, the line in /Views/Web.Config should be:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
For the benefit of anyone developing ASP.NET MVC 5 web apps using Xamarin Studio v5.5.3 on OSX, deleting the /Views/Web.config did not work for me and created other errors.
To fix it, open /Views/Web.config and change all instances of 5.2.0.0 to 5.2.2.0
More details here
Several of the answers point in the right direction, but I was not sure where in the Microsoft Visual Studio for Mac interface I could find the appropriate version number to use for the version part of the factoryType attribute.
For the benefit of other VS for Mac users, the answer is to simply right-click on the Microsoft.AspNet.Mvc package in the Packages list in the solution explorer.
In my case, the package version was "5.2.6" after a package update, so I set the version part of the factoryType attribute to Version=5.2.6.0. This solved the problem.
Changed the version of MvcWebRazorHostFactory to the same version of System.Web.Mvc which resolved my issue.
So apparently some package I got from nuget adds a web.config to the Views folder. In this web.config there were settings for the MvcWebRazorHostFactory. I think this occurred when I added a View to my project using the dialog box.
The solution is to remove the web.config from the Views folder.
I started getting this error in my Razor .cshtml pages in an MVC project following some NuGet package management / upgrading.
I didn't want to remove the Web.config file completely from the Views folder because I had customised it width some <add namespace="..." /> elements. But I noticed that the Version=... in the <host factoryType="..." /> didn't match my version of System.Web.Mvc (checked version in Object Browser).
Altering this version number to match that of my System.Web.Mvc assembly, and restarting Visual Studio, fixed the problem for me (as suggested by Daniel)
This happened to me today. I just made sure the version number for the web.config in the views folder matches the version number for the web.config of the solution.
Hope this helps.
For MacBook users having the Visual Studio 2019, you simply go to the Web.config file and update version of the System.Web.Mvc to that which is in your Nuget packages folder.
Inside your Web project, open "References" tree node.
Look for "Assemblies" folder and open it.
Look for System.Web.Mvc, right click on it, and select "Properties"
A dialog will prompt, read carefully the package full name field and look for the version number. For example, I have this one:
System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
So, in the Web.config (inside Views folder) replace the version number!
In my case, it originally was:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Now I have (look at the Version value):
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Hope it helps!

From where i can find the PublicKeyToken & Version for my <membership> <providers>

I am working with an asp.net mvc web application, and i need to connect to remote domain, so i added the following to my web.config:-
<membership>
<providers>
<add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain1ConnectionString" connectionUsername="....." connectionPassword="....." />
but i am not sure what does Version and PublicKeyToken represetns and from where i can find them ? and if i do not specify these values will my provider be valid ?
Thanks
As that's a regular framework assembly, it will be deployed on GAC; to discover full assembly name you can access that class documentation on MSDN.
There you'll find that class resides on System.Web assembly. Now you can navigate to c:\windows\assembly folder and locate the assembly which matches desired version, right click it and copy the public key token.
Is that information doesn't match the version and public key token on your web.config file, .NET framework can't locate it and, you'll get a missing assembly exception.

ASP.NET Compiler complaining of mismatching framework versions with MiniProfiler

I have an MVC3 project that I upgraded from VS2010 to VS2012. The project also has a reference to MiniProfiler. Our application compiles and runs fine in VS2012 without any warnings/errors. Both assemblies load fine when running with IIS Express. When using the ASP.NET Compiler tool, however, I get the following warning:
Microsoft (R) ASP.NET Compilation Tool version 4.0.30319.17929 Utility
to precompile an ASP.NET application Copyright (C) Microsoft
Corporation. All rights reserved.
(0): warning : The following assembly has dependencies on a version of
the .NET Framework that is higher than the target and might not load
correctly during runtime causing a failure: MiniProfiler,
Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3. The
dependencies are: System.Data.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089. You should either ensure that the
dependent assembly is correct for the target framework, or ensure that
the target framework you are addressing is that of the dependent
assembly.
We don't have an explicit reference to System.Data.Linq. Up until the update to VS2012, we didn't have any errors. The MiniProfiler version is indeed targeting .NET 4.0 (as is our application). What could be causing this warning?
I was finally able to fix it with a tip from this answer. I added the following <add> line in the web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<!-- etc... -->
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- etc... -->
</assemblies>
</compilation>
<system.web>
</configuration>
Did you changed targetFramework inside Web.confing?

Problems with EF 4.3 when deployed

I have EF4.3.1 installed on my local machine.
I created a new web application project and added the framework. I then created a database/model etc. The framework is split over 2 projects 1 DAL, 1 Entities. On my local machine I'm restricted to SQL Express 2008.
Here is the configuration section from web config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
Here is the connection string I use:
<add name="PayDayLoanEntities" connectionString="metadata=res://*/Models.PayDayLoans.csdl|res://*/Models.PayDayLoans.ssdl|res://*/Models.PayDayLoans.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;attachdbfilename="C:\Documents and Settings\John\My Documents\Visual Studio 2010\Projects\IL\WebSite\App_Data\PayDayLoans.mdf";integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
All this works!
On my production machine I use SQL 2008 web edition so, changed the connection string as follows:
<add name="PayDayLoanEntities" connectionString="metadata=res://*/Models.PayDayLoans.csdl|res://*/Models.PayDayLoans.ssdl|res://*/Models.PayDayLoans.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=PayDayLoans;uid=***;pwd=********";integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
However, I get the following error message:
Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The config section refers to 4.3.1 but the error 4.1.0. Anyone know what I'm missing here?
Any help appreciated.
There's a good chance that something in your solution is referencing EF 4.1.0 when built for RELEASE. Perhaps you have a build server that is not updated properly?
Run Fuslogvw (as Administrator or it will silently fail) on your production machine. Start logging bind failures before you start your web application. Fuslogvw will tell you what exactly tried to bind EF 4.1.0.

Unobtrusive Oracle Deployment on Windows Server 2008

I have a .NET 4.0 Web Forms app that I am running with the beta Oracle EF-aware data provider, and I want to perform "unobtrusive" Oracle deployment to a Win2K8 box, as shown in many SO solutions.
There is an existing Oracle Instant Client installation on the Win2K8 box, which I can neither work with nor remove, and it has an entry in the PATH environment variable on the Win2K8 box. According to this SO answer, I do not need to set PATH for my Oracle DLLs, since I have DllPath set in the web.config.
I am following the procedure from here, yet I still get the provider is not compatible with the version of Oracle client error.
Here's my (unsuccessful) setup, as of now:
Oracle DLLs are in my web app's bin directory, and set to Copy Always Do Not Copy.
Platform and Platform Target settings are set to x86 in my local Build Configuration.
32-bit applications are enabled in the app pool (.NET 4.0) on the Win2K8 box.
Oracle DLLs are not present in the GAC, not are they present in the GAC_32 and GAC_64 directories on the Win2K8 box.
My web.config (but not my Win2K8 machine.config) contains this:
<configuration>
<configSections>
<section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<oracle.dataaccess.client>
<settings>
<add name="DllPath" value="C:\inetpub\wwwroot\myapp\bin"></add>
<add name="FetchSize" value="65536"></add>
<add name="StatementCacheSize" value="10"></add>
<add name="TraceFileName" value="c:\temp\odpnet2.log"></add>
<add name="TraceLevel" value="0"></add>
<add name="TraceOption" value="0"></add>
</settings>
</oracle.dataaccess.client>
<system.data>
<!-- Version=4.112.2.50 -->
<DbProviderFactories>
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.112.2.50, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=**<using EZCONNECT format here>**" providerName="System.Data.EntityClient" />
</connectionStrings>
<configuration>
The app itself deploys successfully, and I can run pages that do not reference my Oracle DLLs. But, for those that do reference Oracle, I still get the provider compatibility error.
What am I missing?
Thanks again for the help.
UPDATE: The web app runs on the Win2K8 target with .NET 4.0, EF4.1, and the Oracle EF Provider, completely separate from the other active ODAC install. No PATH variable, no installation from Universal Installer, no Oracle DLLs in GAC.
Case closed. I was missing an Oracle DLL.

Resources