provider with invariant name 'Devart.Data.PostgreSql' is either not registered in the machine or application config file, or could not be loaded - postgresql

I get this error message when using my API with PostGres database.
"The ADO.NET provider with invariant name 'Devart.Data.PostgreSql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details."
I have the feeling I need to install Devart product on my staging and production server to fix the error. Is it right? In case this is right I would like to understand why simply copying or publishing Devart dll is not enough? Normally it should be enough.
In error message I can read "is either not registered". What does it mean to be registered? Is it rehgistered in confi file or I need to do a specific operation on my staging and produciton machine?

You should register configuration information in the DbProviderFactories section of the *.config file:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.PostgreSql" />
<add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version=7.12.1328.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
</system.data>
Replace 7.12.1328.0 here with your actual version.
Refer to https://www.devart.com/dotconnect/postgresql/docs/?deployment.html.

Related

Trying to use DDtek Datadirect Sybase drivers as a provider for Enttiy Framework 6, can't get it configured correctly

Trying to use DDtek Datadirect Sybase drivers as a provider for Enttiy Framework 6, can't get it configured correctly..
It looks like in 3.3 there is no DDtek.Sybase.Entity,
We have a trial version of 4.2 which has the DLL, so I've installed that on.
Here is my providers section of the web.config, where I think the error lives
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,
EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer" />
<provider invariantName="DDTek.Sybase.4.2" type="DDTek.Sybase.Entity.ProviderServices, DDTek.Sybase.Entity,
Version=4.2.0.0, Culture=neutral, PublicKeyToken=c84cd5c63851e072" /
</providers>
</entityFramework>
and here is my connection string
<add name="DefaultConnection" connectionString="host='XXXX.XXX';Pooling=true;Port='6000';UID='XXXXX';Password=XXXXX;Database='XXXX';Min Pool Size=5;Load Balance Timeout=30;Connection Timeout = 30000;Max Pool Size=50;Workstation ID='SPN'; Clone Connection If Needed =true; Fetch Buffer Size = 40960" providerName="DDTek.Sybase.4.2" />
The connection string, minus the providername bit works in 3.3, non EF.
Here is the error I'm getting...
The Entity Framework provider type
'DDTek.Sybase.Entity.ProviderServices, DDTek.Sybase.Entity,
Version=4.2.0.0, Culture=neutral, PublicKeyToken=c84cd5c63851e072'
registered in the application config file for the ADO.NET provider
with invariant name 'DDTek.Sybase.4.2' 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.
Looking at more documentation I changed the name to DDTek.Sybase (default) instead of DDTek.Sybase.4.2 (recommended fro multiple versions installed (which there are, but only one supports EF)
and this is the error I get instead
The Entity Framework provider type
'DDTek.Sybase.Entity.ProviderServices, DDTek.Sybase.Entity,
Version=4.2.0.0, Culture=neutral, PublicKeyToken=c84cd5c63851e072'
registered in the application config file for the ADO.NET provider
with invariant name 'DDTek.Sybase' 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.
Has anyone successfully set this up using the Progress/DataDirect drivers?
I'm 100% noob to Entity Framework, so no idea is too small, or unappreicated
The DataDirect Drivers do not support EF 6.0 as they previously told me, it
only supports 5.0.
So I converted it to work with MSDB, in like 10 min (Most of which was commenting out bits of Sybase + ddtek stuff)
The new connectionstring looked like this
<add name="DefaultConnectionMSold" connectionString="Data Source=XXXXXXXXX;Initial Catalog=my_project;Integrated Security=True" providerName="System.Data.SqlClient"/>

NpgSQL 3 Code First Connection String

I am trying to setup a project with EF6 and NpgSQL 3.x
I took the following steps:
Used Nuget to install Entity Framework 6
List item
Add connections string to .config file using syntax described here: http://www.npgsql.org/doc/connection-string-parameters.html
Used Nuget to install NpgSQL EntityFramework6 package
When I try to connect to the database I get the error:
"Keyword not supported: 'port'."
referring to the port setting in the connection string
if i remove the "port" the connection fails with 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. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
The error message seems like it is trying to connect using SQL server protocol not postgres. Is there any additional steps I need to take to get this setup?
Most of the .config file examples in the documentation appear outdated so I am wondering if need to manually add a setting to the config somewhere.
If anyone has this setup working could you share your .config files thanks.
You're right about : "it is trying to connect using SQL server protocol not postgres", because it's the default provider.
You have to add the Npgsql provider to the DbProviderFactories and EF providers in web.config, then link the connection string to that provider (see providerName), so entityframe can connect to postgresql:
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<connectionStrings>
<add name="CS" connectionString="Server=127.0.0.1;Port=5432;Database=MYDB;User Id=postgres;Password=mypass" providerName="Npgsql" />
</connectionStrings>

Microsoft.Practices.EnterpriseLibrary.Data.DLL but was not handled in user code

Searched google and using Enterprise library data access to connect database.
Installed only data access pack using https://www.nuget.org/packages/EnterpriseLibrary.Data/.
After added to the project, I've set the configuration as follows,
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</configSections>
<dataConfiguration defaultDatabase="dProvider" />
<connectionStrings>
<add name="dProvider" connectionString="server=local;Initial Catalog=n;uid=sa;pwd=pwd"
providerName="System.Data.SqlClient" />
</connectionStrings>
Called through the application like the following,
Database db;
string sqlCommand;
DbCommand dbCommand;
db = DatabaseFactory.CreateDatabase("dProvider"); or DatabaseFactory.CreateDatabase();
After run the application, I got the following exception,
{"Database provider factory not set for the static DatabaseFactory. Set a provider factory invoking the DatabaseFactory.SetProviderFactory method or by specifying custom mappings by calling the DatabaseFactory.SetDatabases method."}
What mistake I made ? How to solve this issue ?
Finally found the answer. It has been occurred because of the configuration section.
I've used version 6, but here I've mentioned like version 5 in the configuration section. So the error has occurred.
I've replaced the configuration section like following, It worked perfectly in good way. :-). Thanks a lot for the helpers.
<configSections>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
and used DataBaseProviderFactory class to create instance.
DatabaseProviderFactory factory = new DatabaseProviderFactory();
db = factory.Create("dProvider");

EF5 Code First Migration problems publishing to IIS

I've created a MVC 4 project which uses EF5 Code First with migrations.
Because I was new to this topic I used the following article.
Now that the development is finished I want to publish to IIS (I use FTP or Web deployment package). So before publishing I changed the connectionstring to the right db server.
But after publishing the site I get an exception when accessing pages which make use of the DB. The exceptions refers to the fact that he can't connect to the database.
Because of these problems I decided to try it out locally on another DB server than the default one "(LocalDB)\v11.0". BTW: "(LocalDB)\v11.0" works like a charm...
While debugging I got a better look at the error.
Here is an image of the error:
What I've already tried:
Generate a sql script by executing "Update-Database -Script
-SourceMigration:$InitialDatabase" in the Package manager console. After I ran this script on the dbserver to create the db. Tables were
created but the error was still there.
I changed my connectionstring to all kinds of combination with no
results
I already used a custom user for the app pool in ISS and gave this user full rights to the DB server and the db.
Here is the most important part of my web.config:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=LOCALHOST\MSSQLSERVER;Initial Catalog=ProjectX;Integrated Security=TRUE;MultipleActiveResultSets=True" />
</connectionStrings>
And
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=LOCALHOST\MSSQLSERVER; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
My DBCcontext class constructor looks like
public DBContext(): base("DefaultConnection")
{
}
I guess I am missing something, this is the first time I use EF Code First with migrations.
This problem is really driving me crazy. I am out of ideas.
Just found out that the problem was caused by the connectionstring.
The string was incorrect, seems like you if you have a default SQL Server you just need to use
"Data Source=LOCALHOST".
I guess because of all the problems I had that day with the deployment i overlooked the easy parts. Yust make sure you the following things are true when you have problems like I did:
Your connectionstring has the same name as your DBContext. Another sollution could be to do like i did and add the connectionstring name to the base:
public DBContext(): base("DefaultConnection")
{
}
If you also have the defaultconnectionfactory set. Make sure to also update the Data Source there. This was one of the problems I struggled with. I didn't check the bottom of my web.config ...
If the problem still persists you can use EF profiler to have a look at the connectionstring when your app of site is accessing the DB.

Change default location of LocalDb

I am programming with EF5-code first and want to use LocalDb. How can I change the default location of LocalDb database file? Default location is %USERPROFILE% directory according to http://blogs.msdn.com/b/sqlexpress/archive/2011/10/28/localdb-where-is-my-database.aspx
Previously I was using SqlCe DbConnectionFactory which accepts a parameter for database path/name. If I use AttachDbFileName parameter then it raises an exception if database doesn't exist (it's supposed to create it!).
I got this working thanks to this post. The answer is simple. Basically I added
<connectionStrings>
<add name="DataModel.Context" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=database;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\database.mdf" providerName="System.Data.SqlClient" />
to the configuration section of app.config and it magically replaced the "database" with my actuall database (DbContext) name. EF code first also works perfectly to create the database if it doesn't exist.