Error- Unable to determine the provider name for provider factory of type 'Npgsql.NpgsqlFactory' in .net core 5 with npgsql - entity-framework-6

Trying to run a .Net Core 5 Web API project but when I am trying to connecting npgsql getting
"provider name"
error .
I am using connectionStrings in App.config and DbProviderFactories in machine.config file.
trying to connect npgsql in WebApiConfig file
var connection = new pgsql.NpgsqlConnection(Environment.GetEnvironmentVariable("dbcontext"));
var db = new DbContext(connection, true);
db.Database.Initialize(true);
Getting this error
enter image description here
Someone have an idea? how can I resolved this error in .Net core.

machine.config is not supported on .NET Core (https://github.com/dotnet/runtime/issues/32307).
For managing connection strings with ASP.NET, see these docs and/or this tutorial.

Related

migrate database from one MVC project to another

I am using Visual Studio 2013. Unfortunately I am facing some problems with my MVC project. So I created a new project and I need to fetch database to my new project but can't figure out how to fetch database. I am using data first approach, entity framework and IIS Express localhost.
Update:
I copied connection string from web.config of old project and pasted it over new project's connection string.(Note I first created ado.net entity data model in new project and then pasted string over its connection string).
Now in server explorer window > data connections my Entities connection has changed to defaultconnection and I get exception The underlying provider failed on Open on executing query of new projects database. But I am unable to fetch old database tables.
Your DBContext likely has the name of the database connection in one of it's constructors.
This corresponds to the name of a connection string the web.config.
So move that configuration to your new web config and make sure your new DbContext references the correct name.

How can I access the DataContext via Project Dependency?

I have setup a MVC 5 Solution that has two sub projects. 1) The MVC Application and 2) an API.
I am using EF 6 in the MVC Application, and I have set up a project dependency from the API to the MVC application. However, when I try to use scaffolding in the API project, I get this error: "Unable to retrieve metadata for Chat.Message. No connection string named "ChatEntities" could be found in the application config file.
Any advice on how to resolve this error?
Just copy connection string to the web.config file in API project.

how to create tables on azure and connect them with VS2013

I have built my MVC 5 project with a database using entity framework db first. I published my website but had problems with my database.after lots of research to solve the problem,i figured to build my database on azure since it's only 2 tables and copied the connection string to the web.config file on my MVC 5 project.
when publishing again with the new connection string update, an error showed indicating that can't find the database:
The system cannot find the file specified
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
This is what the azure offered me as a connection String:
Server=tcp:idud662mdp.database.windows.net,1433;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
I have modified it and this is my connectionString:
<add name="DataEntryNew" connectionString ="Data Source=idud662mdp.database.windows.net;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password=My-Pass;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient"/>
What's going wrong?
Your connection string is not the same one as provided by Azure. Try changing the DataEntryNew tag in the web.config file to:
<add name="DataEntryNew" connectionString ="Server=tcp:idud662mdp.database.windows.net,1433;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient"/>

Which connection string WSAT uses

I create a new ASP.NET MVC project with internet template.
I build the solution.
I open ASP.NET Web Site Administration Tool (WSAT).
I click the security tab
I get this error:
"Unable to connect to SQL Server database."
I am using Visual Studio 2012 and SQLServer Express 2012.
I don't have IIS installed (other then what ships with Visual Studio).
The Connection String from the new project:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication2-20130804051506;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication2-20130804051506.mdf" providerName="System.Data.SqlClient" />
It is worth mentioning that I did not change anything in the web.config after its initial creation and that MVC project seems to be working properly e.g. I am able to register and login and then see that data in the (LocalDb)\v11.0.
I read on other posts that the connection string from machine.config is sometimes used instead of the one from web.config.
I have a two machine.config files, one under C:\Windows\Microsoft.NET\Framework\config\v4.0.30319 and the other under C:\Windows\Microsoft.NET\Framework\CONFIG\v2.0.50727
When is a machine.config's connection string is used instead of my web.config's connection string?
I want to use the (LocalDb)\v11.0 data source, why does WSAT unable to connect to it?
From http://forums.asp.net/t/1483981.aspx/1 :
by default, the membership / role provider uses the "localSQLServer" connection string which is set to point to a local SQL Express database from the root web.config. In most cases, the server do not have SQL express installed and you will get this error.
By clearing the connection strings should reveal those errors.

Firebird and ASP.NET MVC

Have just started converting an existing job tracking system into an ASP.NET MVC application. I'm failing miserably at getting this thing off the ground. I'm getting this error
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
With the following connection string
<add name="ApplicationServices"
connectionString="User ID=sysdba;Password=masterkey;Database=localhost:C:\\USINGFIREBIRD.FDB;"
providerName="FirebirdSql.Data.FirebirdClient" />
FirebirdClient has been added to windir\assembly using gcutil
This is probably a very dumb question, but does USINGFIREBIRD.FDB have to exist? Or will it be automatically created? Regardless, with the file created it does not work.
Edit:
Ok so in the end I was having so much trouble that I decided to start fresh.
First thing I discovered was that the .NET 4 assembly cache has moved to windows\Microsoft.NET\assembly. I saw that FirebirdClient was not in here so I had to figure out how to get it in there. I used Visual studio 2010 command prompt to add the assembly with GCUTIL.
Then I followed the information here
Then create a new asp.net mvc project, register your database in the server explorer, then add add an ado.net model class and have it auto generated from your database.
I'm writing this rather hastily as I'm about to leave work, hope it helps someone.
The file must exist and it must be a proper Firebird database, ie you can't just create an empty file named "USINGFIREBIRD.FDB". To create an Firebird database you can use the isql command line tool installed with Firebird.
BTW the error message says The server was not found or was not accessible - are you sure the Firebird service is running?
Your connection string part "Database=localhost:C:\\USINGFIREBIRD.FDB;" is wrong. If you database is a file you don't need the "localhost" just the db file path.
Here you can see valid connection strings for Firebird.

Resources