I have updated my project from EF5 to EF6, using NuGet, but am getting an error now as soon as my application tried to query the database.
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.
I think the issue is with my data project's App.Config, which resembles 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>
<connectionStrings>
<add name="AccuFinanceEntities" connectionString="metadata=res://*/AccuFinanceEntities.csdl|res://*/AccuFinanceEntities.ssdl|res://*/AccuFinanceEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=laptop;initial catalog=mydb;Integrated Security=True;MultipleActiveResultSets=True;App=AccuFinance"" providerName="System.Data.EntityClient" />
</connectionStrings>
<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>
</configuration>
My web.config only has a connection string applied:
<connectionStrings>
<!--SERVER -->
<!--LOCAL-->
<add name="AccuFinanceEntities" connectionString="metadata=res://*/AccuFinanceEntities.csdl|res://*/AccuFinanceEntities.ssdl|res://*/AccuFinanceEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=laptop;initial catalog=mydb;Integrated Security=True;MultipleActiveResultSets=True;App=AccuFinance"" providerName="System.Data.EntityClient" />
</connectionStrings>
I think I need to add or remove something from one of these, but not sure which. It worked fine under EF5. Project compiles and builds, and I can edit my EDMX file (I can update model from database).
What am I doing wrong?
Related
I created an application in c# with wpf using EntityFramework.
When I create the setup it works fine on my computer but when I install it on another computer I get this error
A file activation error occured. The physical file name \Data\myDb.mdf may be incorrect. Diagnose and correct additionnal errors, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Here is my App.config
<?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>
<connectionStrings>
<add name="myConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;
AttachDbFileName='|DataDirectory|\Data\myDb.mdf';
Initial Catalog=myDb.mdf; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
You could try to set the value for |DataDirectory| during runtime:
AppDomain.CurrentDomain.SetData("DataDirectory", #"C:\Program Files (x86)\Company\AppFolder\")
Or replace |DataDirectory| with an absolute path in your configuration file.
I have created my c# application using entity framework. The app config generated when creating data model looks like following. I want to change the name of the database and run application with a different database by running all the query changes I made when making the application. I created a new database with a different name and added all the query changes to it. And when I run the application it shows that table names doesn't exist though they exist already in the database.
My app config looks like this.
the changed config line with new database name is in the comments.
<?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" />
</startup>
<connectionStrings>
<add name="RIT_Allocation_Entities" connectionString="metadata=res://*/DataControllers.JobAllocationDataModel.csdl|res://*/DataControllers.JobAllocationDataModel.ssdl|res://*/DataControllers.JobAllocationDataModel.msl;provider=System.Data.SqlClient;provider connection string='data source=.;initial catalog="RIT_POS_DB ALUTECH HO 12112018";integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
<!-- <add name="RIT_Allocation_Entities" connectionString="metadata=res://*/DataControllers.JobAllocationDataModel.csdl|res://*/DataControllers.JobAllocationDataModel.ssdl|res://*/DataControllers.JobAllocationDataModel.msl;provider=System.Data.SqlClient;provider connection string='data source=.;initial catalog="RIT_POS_DATABASE";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>
How to change my database and add the table changes to it and run my application? Or do I need to change the database name somewhere else in the application?
I'm working with one project creating the application.
I am using Entity framework 6.1.3 version.
I am using Oracle 11g version.
I am trying to connect to Oracle through Entity framework.
I am facing issue while trying to open connection.
Below is my config file and code to connect:
----------
<?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>
<connectionStrings>
<add name="FOLADB" connectionString="Data Source=HRFOLATEST1;User id=***;Password=***;" providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>
<entityFramework>
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, 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" />-->
<provider invariantName="Oracle.ManagedDataAccessClient" type="Oracle.ManagedDataAccessClient.OracleClientFactory, Oracle.ManagedDataAccessClient" />
</providers>
</entityFramework>
</configuration>
string connectionString = ConfigurationManager.ConnectionStrings["SConnectionString"].ToString();
OracleConnection connSSTrack = new OracleConnection(connectionString);
connSSTrack.Open();
I am getting the below error:
ORA-12154: TNS:could not resolve the connect identifier specified.
When I am using the same connection string in another asp.net application,it is working fine.
Check your TNS settings. You can supply them is your connect string or find them in your tnsnames.ora. https://blog.vijay.name/2012/11/oracle-managed-odp-net/
I have solution with 3 projects:
1) - library
2) - test (windows forms application)
3) - windows service
Library uses Entity Framework. When i link it to test application it works. My App.config (for test application) looks like this:
<?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="ITSBPEntities1" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.131;initial catalog=ITSBP;persist security info=True;user id=user;password=pass;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<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>
I've referenced to library in service also. I installed it and run, but when it try to use Entity Framework some exception is thrown, there is log:
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
App.config in service project is copy-pasted from test application. EntityFramework.dll exists in debug folder.
How do I change my app.config or Migration Configuration.cs file so Entity Framework uses a local SDF file instead of a local SQL Server instance ? I am using EF 6.1.
Thanks
<?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>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
You should just be able to specify the ProviderName in the connection string to your database.
<connectionStrings>
<add name="DataModelContext"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=location\cfdb.sdf"/>