How do I get Effort to work with EntityFramework? - c#

OVERVIEW
Using Fitnesse with EF6, can't get Effort to start up.
I've tried every trick in all the posts I can find.
All the posts say to either call 'RegisterProvider', or add a config section. Neither is working.
So far:
I have "Effort.Provider" in the DbProviderFactories section in machine.config.
I have Effort.Provider showing up when I look at DbProviderFactories.GetFactoryClasses();
ProcMon shows that it is looking for and finding Effort.dll.
Result:
Any of
DbConnectionFactory.CreateTransient();
Effort.EntityConnectionFactory.CreateTransient(connectionString);
DbProviderFactory dataFactory = DbProviderFactories.GetFactory(dt.Rows[5]);
throw
Effort.Exceptions.EffortException: The Effort library failed to register
Also tried:
"Effort.Provider" in the entityFramework section of Runner.exe.config but couldn't get that to work. Just crashed the app.
Uninstalling EF and Effort.EF6 and re-installing. No visible effect.
Calling Effort.Provider.EffortProviderConfiguration.RegisterProvider(); from a class constructor and various startup locations. Effort.Provider never showed up in DbProviderFactories.GetFactoryClasses();
With "Effort.Provider" in the DbProviderFactories section in app.config, it shows up in GetFactoryClasses just as well as machine.config.
Using:
Windows 10
.Net 4.6
VS 2016
EF 6.1.2 (although it says 6.1.3 is installed, not sure what that means)
Do I need to register a DLL or something? Nothing in the instructions about that.
More Details:
App.config
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
<system.data>
<DbProviderFactories>
<add name="Effort.Provider" invariant="Effort.Provider" description="Effort.Provider" type="Effort.Provider.EffortProviderFactory, Effort" />
</DbProviderFactories>
</system.data>
</configuration>

It looks like you need to register the "entityFramework" config section in the app.config file.
<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>
<providers>
<provider invariantName="Effort.Provider" type="Effort.Provider.EffortProviderServices,Effort" />
</providers>
</entityFramework>
Then in your code create the Effort connection and pass it to your DbContext. If you don't already have a constructor that takes an object of type System.Data.Common.DbConnection, create one.
System.Data.Common.DbConnection connection = DbConnectionFactory.CreateTransient();
var context = new MyContext(connection);
I would also recommend setting a connectionString in your app.config. I believe the call to CreateTransient creates a connection for you, but if your code under test has code that creates another dbContext somewhere, Effort will look to the app.config to get that information. Below is an example that will create a transient database so that all operations completed in one test do not affect another test.
<add name="DefaultConnection" connectionString="Data Source=in-process;IsTransient=true" providerName="Effort.Provider" />

Related

The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered

I have a .NET Core React Web application that calls into a Class Library with a reference to the Entity Framework. I'm using a database that is stored in Azure, and every time I query my database, I get this exception:
System.ArgumentException: 'The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.'
InnerException: ArgumentException: The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.
I'm thinking I don't have something configured properly in my Web.config/App.config files but I'm not sure.
Web.config file in my web app:
<configuration>
<connectionStrings>
<add name="JATEntities"
connectionString="Server=tcp:[someserver].database.windows.net,1433;Database=JAT;persist security info=True;user id=[userid];password=[password];MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
My App.Config in my class library:
<?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>
<connectionStrings>
<add name="JATEntities"
connectionString="Server=tcp:[someserver].database.windows.net,1433;Database=JAT;persist security info=True;user id=[userid];password=[password];MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Here's the code that I'm calling in my class library:
public class MyClass
{
// I've tried this as it seems to have worked for some people
private static string __hack = typeof(SqlProviderServices).ToString();
public void MyMethod()
{
using (var context = new JATEntities())
{
var query = from listing in context.CurrentListings
where listing.Id == id
select listing;
}
}
}
I've also referenced the App.config file from my ClassLibrary into my Web App project, but that doesn't seem to help.
[External Code]
JAT.DB.dll!JAT.DB.Repo.Repo.GetCurrentListingById(int id) Line 22
at C:\Users\Jungle\source\repos\JAT\JAT.DB\Repo\Repo.cs(22)
JAT.Client.dll!JAT.Client.Controllers.SearchController.FirstMethod() Line 25
at C:\Users\Jungle\source\repos\JAT\JAT.Client\Controllers\SearchController.cs(25)
[External Code]
What worked for me was upgrading to Visual Studio 2019, and creating a new .Net core web application and .net core class library and then moving all my code from my old solution into the new one.

Entity Framework provider error

Hello guys I am strugling with connecting to sql database server. I am using Entity framework v6 and trying code first approach for the first time. Below I will show you my app.config file and error message I get I checked out similar questions and most of answers were about missing EntityFramework.SqlServer.dll I have this dll referenced
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="HotelDB"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
</connectionStrings>
</configuration>
Error Message:
System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Have you found a solution for this problem? Otherwise you could take a look here: Entity Framework Provider type could not be loaded?
Most of the time when I see this exception it's because the web application doesn't have Entity Framework installed (and / or missing the EntityFramework.SqlServer.dll).
So to give an example, if you have 2 projects in a solution:
WebApp
DataAccess
and with Entity Framework installed in the DataAccess project. When wanting to call a method on a class (for example a repository) from the DataAccess project within the WebApp, 2 things are needed:
WebApp needs a reference to DataAccess
Webapp also needs EF to be installed
When DataAccess has EF installed and then added as a reference to WebApp, the WebApp project will (normally) also install EF. Sometimes in unexpected situations the installation of EF in the WebApp fails. Therefore not adding the needed references and showing the exception message you mentioned. Hopefully this answer will help some others.
I also had a similar problem
My problem was solved by doing the following:
If nothing of the solutions worked then check both the packages.config of WebApp and DataAccess for the version of Entity Framework. In case you see or don't see the entry of EF in the packages.config file of WebApp, go to the reference and delete the EF from WebApp and install it again using the package manager console giving the following command:
Install-Package "EntityFramework" -Version (Version number)
where Version number is the version that's present in the packages.config of DataAccess.
Example:
Install-Package "EntityFramework" -Version "6.1.3"

Getting an error from Entity Framework(type initializer exception)

I' am getting this:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
error in my Entity Framework.
I read this Question and the possible answers, however non of them worked for me. Here is my App.config file:
<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>
<connectionStrings>
<add name="SalesReportEntities"
connectionString="metadata=res://*/SalesReportModel.csdl
|res://*/SalesReportModel.ssdl
|res://*/SalesReportModel.msl;
provider=System.Data.SqlClient;
provider connection string="data source=.;
initial catalog=Training;
integrated security=True;
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
What other possible things can cause this error?
I can offer a few suggestions and some are similar to the thread you already looked at:
Can you use SQL Management Studio and verify this database exists and has tables and is currently in a responsive state?
Put your 'connectionStrings' section after the < providers > node.
Your parameter value is 'v11.0' which seems to be targeting a version of SQL Server 2012. Mine that I am looking at now is similar to yours but just states: "mssqllocaldb". Which I believe is just the default instance of sql server from the connection you specify.
Uninstall Entity Framework completely and get it again from NuGet. I assume you are using Visual Studio so in 2015 it is Tools>NuGet Package Manager>Manage NuGet Packages. Uninstall, check your app config and 'References' that 'EntityFramework' is gone. Reinstall and check your settings again.
Are you trying to reference a project that entity lives in in another project or is it self contained? If so you need to target EF just like you were on the source project with adding EF to that project and a config the same.
You may also want to post the entire exception for better answers too.

Using the ADO.NET Entity Framework with the Advantage Database Server

I'm creating and WPF application using the MVVM in VS 2013; first implementation was with SQL server and it worked like a charm.
Second phase is to have support for Advantage Sybase. For this I have downloaded Advantage Data Provier to have the connection in connection drop down list ( http://www.codeguru.com/csharp/.net/article.php/c17027/Using-the-ADONET-Entity-Framework-with-the-Advantage-Database-Server.htm ).
For VS 2013 there is a problem with this and the workaround is to manually edit the registry to have this provider (http://blog.nwoolls.com/2012/07/25/registering-missing-data-providers-with-visual-studio-2012/).
Now I have the provider in the drop down, I can select the provider, but when I try to generate the script for data base generation I have a weird error:
ERROR:
"
Could not find the appropriate DbProviderManifest to generate the SSDL. The supplied provider Manifest token '2008' is not valid.
"
Any ideas on how to use the DB Provider correctly?
First, VS 2013 is not yet officially supported by Advantage Database Server. I believe official support may be available once ADS 12.0 is released.
But.... I did get a chance to try it out and it is working.
Be sure to that you are using the 11.1 ADS .Net dataprovider. It includes support for Entity Framework 5 (As far as In know, nothing from ADS includes support for EF6 at this time)
Export the 4 keys mentioned in your second article from Nate Wools. In my case I exported from VS 2012 (11.0 in the registry path). Full find/replace on 11.0 -> 12.0 including the assembly version for Microsoft.VisualStudio.Data.Framework
(Disclaimer, I've not had a chance to try MVVM, just a plain Windows Form app, but it worked well)
App.Config that was automatically created and updated. Maybe check against yours?
<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Advantage.Data.Provider;provider connection string="Data Source=E:\ADS\School\School.add;User ID=adssys"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>

No Entity Framework provider found ... with invariant name 'System.Data.SqlClient'

None of the posts on here has seemed to address this specific version of my error but I may just be missing something...
Situation:
MVC website consumes a WCF service. Data is saved in the WCF service. Both are running
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
Both have connection string:
<add name="SiteTrackerEntities" connectionString="metadata=res://*/VisitorInformation.csdl|res://*/VisitorInformation.ssdl|res://*/VisitorInformation.msl;provider=System.Data.SqlClient;provider connection string="data source=BADLANDS\;initial catalog=SiteTracker;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Site runs until I actually try to save to the database in the WCF service using (errors on second line)...
SiteTrackerEntities db = new SiteTrackerEntities();
db.Entry(visitorData).State = System.Data.Entity.EntityState.Added;
I then get this lovely error:
VisitorInformation.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Made sure that both are using the same version of EF (6.0). Check.
Tried to enter the provider name in the connection string but already using providerName="System.Data.EntityClient"
Tried removing and reinstalling EF using PM console. Check.
Manually removed Ef references and readded them. Check.
WCF Service has reference to Entity.Framework.SqlServer (version 6.0.0.0). Check.
MVC application has connection string to the database that is only used in the WCF service (odd that it needs it but okay). Check.
What am I missing?
Make sure you have something similar to the following in your Web.config or App.config.
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

Categories

Resources