Entity Data Model silently quits - asp.net

Before I describe the problem, I want to let you know that I went over like 30 different answers on Stack Overflow that seems to be similar to my problem, but none of thee solution helped me solve this.
The issue:
The wizard while creating ADP.NET Entity Data Model quits after I click "Next" in the "Choose Your Data Connection" step without any error or notification, the window just closes and no file is generated. There is nothing in the output or error window as well.
I have a C# .NET 4.6.1 web form project with the following packages:
Entity Framework 6.2.0
MySql.Data 8.0.11
MySql.Data Entities 6.8.3
MySql.Data Entity 6.10.7
MySql.Web 8.0.11
I clean and rebuild the project, load VS with Administer account, tried to remove connections from server explorer and try again, I have the latest .NET connector installed, but nothing helped.
Related Web.cofig parts:
<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="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>

Related

.Net core 5.0 console app referencing a model building in .Net framework4.7.2

I have a entity framework Data access layer building in .Net framework 4.7.2
And I am trying to reference it from .Net core console app.
I keep getting the error
The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
I have added the below code based on the suggestions on web, but then the error change to a different method which uses system.configuration and the error goes 'cannot initialize the configuration' system.data is invalid config section
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, EntityFramework6.Npgsql" />
</entityFramework>
<system.data>
<DbProviderFactories>
<!--<add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version= 7.17.1583.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />-->
<!--<add name="Npgsql Provider" invariant="Npgsql" description=".NET Framework Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />-->
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
<remove invariant="Npgsql" /><add name="Npgsql Provider" invariant="Npgsql" description=".NET Framework Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /></DbProviderFactories>
</system.data>
For .NET Core you need to call DbProviderFactories.RegisterFactory instead of using config files.
System.Data.Common.DbProviderFactories.RegisterFactory("NpgSql", Npgsql.NpgsqlFactory.Instance);

Config Builder Not Finding Environment Variable

When I view the connection string while debugging, the value is "abc"; not what I've set the Windows environment variable to.
web.config
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</builders>
</configBuilders>
<connectionStrings configBuilders="Environment">
<add name="myConnection" connectionString="abc" providerName="System.Data.SqlClient"/
</connectionStrings>
I've double checked that the correct Nuget packages are installed, that the framework is correctly on 4.7.2, that my spelling is correct, and I've read the Microsoft docs on Configuration Builders several times.
In the Microsoft document linked above, Configuration builders for ASP.NET, there exists the following footnote:
Note: You might need to exit and restart Visual Studio to see changes in environment variables.
That fixed it.

Membership and Role Providers when using Oracle Managed Driver

I had some 32bit/64bit issues in one of my web applications after the DB was upgraded to 64 bit 12C and after researching the problems I had encountered, the almost universal answer was "Use Managed Driver and not worry about 32/64 bit issue". So I did. I
downloaded and installed "ODAC 12c Release 4 and Oracle Developer Tools for Visual Studio (12.1.0.2.4)" from here,
removed references to Oracle.Web and Oracle.DataAccess (unmanaged
drivers) in my app and added reference to new managed driver "Oracle.ManagedDataAccess"
changed all the "using Oracle.Web", "using Oracle.DataAccess.Client"
to "using Oracle.ManagedDataAccess.Client"
But I cannot find one document that tells me how web config file needs to be modified to use managed driver.
Do I need to make any changes to <connectionStrings> section?
Do I need to add additional sections to make use of managed driver?
What do I need to change in Membership and Role Providers sections? The existing providers refer to Oracle.Web.Security.OracleRoleProvider and once upgrading to Managed version, all references to Oracle.Web and Oracle.DataAccess has to be removed.
If anyone has gone through the pain, please share your solutions to these, any other issues I might run into once these are resolved.
This is a sample of current web config file that I think needs to be changed/removed:
<connectionStrings>
<clear/>
<add name="MSAConnectionString" connectionString="User Id=Some_User;Password=SomePwd;Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.20.30.40)(PORT = 1521)))(CONNECT_DATA =(SID = MSA))); Min Pool Size=10;Max Pool Size=300;Incr Pool Size=5;Decr Pool Size=2;"/>
</connectionStrings>
<compilation defaultLanguage="c#" debug="true" targetFramework="4.0">
<assemblies>// next two line will have to be removed, since DLLs no longer referenced
<add assembly="Oracle.DataAccess, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="Oracle.Web, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<membership defaultProvider="DSSOracleMembershipProvider">
<providers>
<add name="DSSOracleMembershipProvider" type="Oracle.Web.Security.OracleMembershipProvider, Oracle.Web, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionStringName="MSAConnectionString" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="4" minRequiredPasswordLength="9" passwordAttemptWindow="8"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="DSSOracleRoleProvider">
<providers>
<add name="DSSOracleRoleProvider" type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionStringName="MSAConnectionString" applicationName="/"/>
</providers>
</roleManager>
A few thoughts:
1) Membership is part of Oracle.Web - so you will still need those references - I like to add this to the runtime section in the web.config for good measure:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.Web" publicKeyToken="89b483f429c47342" />
<bindingRedirect oldVersion="0.0.0.0-4.121.2.1" newVersion="4.121.2.1" />
</dependentAssembly>
</assemblyBinding>
2) VS2015 NuGet can help you get the Oracle managed client installed; however, it could be as simple as global substituting Oracle.ManagedDataAccess.Client for Oracle.DataAccess.Client. (Leave Oracle.Web alone!)
3) additional tuning for your ADO.net pool may be required (in connection strings) - see here: ODP.NET error in IIS: ORA-12357 Network Session End of file
Also the 2.x drivers are for ASP.NET 2.0 - the 4.x are ASP.NET 4.0 - looks like your pointing to the wrong framework.

SQLite 1.0.101.0 and entityframework 6.1.3, using LINQ, will not run

I have developed a windows service that worked well but wanted to add access to SQLite databases. I developed a data manager project within the windows service to add the SQLite data handling. This was developed using VS2015.
The entity framework side of things worked well and built a model of the SQLite database and the service would start and run properly. The connection to the database also worked but when an attempt was made to run a query, I got the following error:
"Schema specified is not valid. Errors:
Video.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. 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."
The problem is that when I add the configuration and entity framework sections to the config file, the service won't start, giving the following error:
"The Media Sync Service service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion."
Here are the configuration and entity framework sections:
<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" />
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
Has anyone else had this problem? I would be very grateful for any advice as to how to fix this.

TransactionScope and SQLite database gets locked

I am trying to use Entity Framework 6 with SQLite and running into a database locked issue when trying to use TransactionScope. Here is my code:
using (var txn = new TransactionScope())
{
using (var ctx = new CalibreContext())
{
var book = ctx.Books.First(x => x.Id == 2);
var author = ctx.Authors.First(x => x.Id == 3);
book.Authors.Add(author);
ctx.SaveChanges();
}
txn.Complete();
}
First line var book = ctx.Books.First(x => x.Id == 2); executes ok. but then once I move on to the next one I get an exception saying that my database is locked. Here is my app config:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<connectionStrings>
<add name="CalibreContext" connectionString="Data Source=metadata.db" providerName="System.Data.SQLite.EF6" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".Net Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="Calibre.Dal.Ef.SQLiteConnectionFactory, Calibre.Dal.Ef" />
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
</configuration>
I need to use TransactionScope because in addition to performing a DB operation, I also have to perform a file system operation that I plan on adding to the same transaction (currently not there).
I was experiencing a similar issue. Just to be clear, the error I got on the second query was "the underlying provider failed on Open" (but the reason for the Open failure was that the database was locked).
Apparently the issue is related to MSDTC (TransactionScope is tightly coupled to MSDTC).
I found a community addition to an MSDN page which in turn references this blog post
... which states that transactions are "promoted" to MSDTC transactions if a connection is closed and reopened. Which EF does by default. Normally this is a good thing -- you don't want database handles hanging around forever -- but in this case that behavior gets in the way.
The solution is to explicitly open the database connection:
using (var txn = new TransactionScope())
{
using (var ctx = new CalibreContext())
{
ctx.Connection.Open();
// ... remainder as before ...
Alternatively, if all your CalibreContext objects are short-lived, you could conceivably open the connection in the CalibreContext constructor.
This seems to have fixed my issue. I'll post an update if I have anything else to report.
One common situation to cause this problem is that another application is accessing the same database.
In my situation it’s because that I opened the database with DB Browser for SQLite, deleted a database table and not applying the changes.
Clicking Write Changes (or Revert Changes or Close Database) and the error will be gone.
(Taken from http://redino.net/blog/2017/03/net-sqlite-database-locked)

Resources