Skip to main content

Initial Npgsql2 provider factory support added to cvs

UPDATE: Thomas Burkhart sent me a mail telling me that this configuration syntax doesn't work on ms.net 2.0. This is the version which works:

<?xml version="1.0" encoding="iso-8859-1" ?>
<configuration>

<system.data>
<DbProviderFactories>

<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />

</DbProviderFactories>
</system.data>

</configuration>


Thomas said that "the tags are case sensitive and the must be outside any <applicationSettings>"


Thank you Thomas for your feedback which, for sure will help others to get their configuration up and running. I will check with Mono guys to see why my original configuration worked.




Hi all!

Today I committed an initial support for provider factory to Npgsql2.

This will allow ado.net 2.0 users to work with Npgsql using ado.net generic coding.

In order to use it, you have to add the following xml config in your machine.config or yourapp.exe.config file:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<appsettings>

<system.data>
<dbproviderfactories>

<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7">
</add>
</dbproviderfactories>
</system.data>
</appsettings>
</configuration>


P.S.: Sorry for indentation lacking. I don't know how to add it on blogger :(

Note that this is the full contents of a yourapp.exe.config file. If you are changing the machine.config file, just add the "add name=..." section.

The key elements here are the invariant name which will be used in your application when returning the provider factory. In this case it is defined as "Npgsql". But you can specify whatever you want.


That's it! If everything is ok, you will be able to write some code like that, to connect to postgresql:


using System;
using System.Data;
using System.Data.Common;


public class c
{
public static void Main(String[] args)
{

DbProviderFactory factory = DbProviderFactories.GetFactory("Npgsql");

DbConnection conn = factory.CreateConnection();

conn.ConnectionString = "Server=127.0.0.1;User id=npgsql_tests;password=npgsql_tests;";

conn.Open();

conn.Close();


}
}


Enjoy!


P.S.: Npgsql2 code is found in Npgsql2 cvs module. See here for more info about how to get it.

Warning: This is a very early code, so bugs still exist and there are things missing. Basic functionality should work ok.



Comments

Anonymous said…
Hi Francisco, I've been using the cvs version and it is working great. One note, on the .net20 framework I found you need to put the <system.data> information in the <configuration> section, outside of the <appSettings>.

Great work, cheers!
Dan
Anonymous said…
Hi Francisco,
many thanks for your good work. I downloaded the CVS version, compiled it, made the entries in machine.config and it seems to work quite well.

Do you have any intention to build a configuration utility (DbProviderConfigurationHandler?) so that you can connect to it using the Server Explorer in Visual Studio?

Kind regards
Trevor D'Arcy-Evans
Anonymous said…
Boa tarde francisco. Baixei sua versão do cvs e estou usando aqui seu provider com o factory no .net 2.0.
Mas acabei me deparando com um problema. Tenho um banco postgres em UTF8, e ao tentar salvar uma string com acentos ele diz que não aceita a sequencia de bytes:
ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xe97374
A sequencia que mandei foi "Téste Ç" (sem as aspas)

Chequei o Request.ContentEncoding do aspnet e ele está em UTF8.

Pode me dar alguma informação sobre este problema?
Aguardo seu contato.
junalmeida@msn.com; junalmeida@gmail.com
Anonymous said…
For people having the same problem as Marcos Jr. ("invalid byte sequence" when trying to insert accented characters in UTF8 encoded databases):

Just create your database with the default encoding (SQL_ASCII) and you should be able to insert and retrieve accented characters fine :)

Don´t know the logic behind this (hints someone?), but worked like a charm for me.
alex said…
Then we will go into the lock and in a few minutes we shall be on the adderall lake.. After considerable whispering between Jane and her mother, the former withdrew, and sent in by the Irish girl a waiter with a basket of soda biscuit, a thyroid pitcher of water, and some glasses.. But on the amoxicillin first appearance of my double--whom I sent on this fatal Monday to the fifth meeting--he was the sixty-seventh man who entered the room.. Atrocious! she exclaimed. clonazepam. Let us, however, keep to the fact--this is the key to the theory of repression--that the second system is capable of occupying an idea only when it is in amoxicillin position to check the development of pain emanating from it.. Lick him! Lick him! exclaimed Buller. celexa. Her daughter having completed her education at the best boarding-school in fluoxetine Philadelphia, and her son being about to graduate at Princeton, the mother had planned with her children a tour to Niagara and the lakes, returning by way of Boston.. It compels us to pursue the lisinopril inner meaning of the dream in these productions.. Got a pencil? He produced the bit of cardboard; Ross fished up a chewed stump of lead pencil, took it in cold, stiff fingers, and disfigured the square with eccentric thyroid scribblings.. All manifestations disappeared as a result of a lengthy sojourn in the country, bodily exercise, and the return lidoderm of physical strength after the termination of the period of puberty.. She's just outside, meanderin' in the road--kinder shy, ye celebrex know, at first.. His parents came home late and went to bed while viagra he was feigning sleep.. The track synthroid couldn't have been in better condition.. Let pretend we ain't here and he'll go away, motrin breathed Abner.. And I had not been at work a year before I found I was living two lives, one real and one merely functional--for two sets of people, one my parish, whom I loved, fioricet and the other a vague public, for whom I did not care two straws...
alex said…
Then we will go into the lock and in a few minutes we shall be on the clindamycin lake.. After considerable whispering between Jane and her mother, the former withdrew, and sent in by the Irish girl a waiter with a basket of soda biscuit, a acetaminophen pitcher of water, and some glasses.. But on the claritin first appearance of my double--whom I sent on this fatal Monday to the fifth meeting--he was the sixty-seventh man who entered the room.. Atrocious! she exclaimed. oxycontin. Let us, however, keep to the fact--this is the key to the theory of repression--that the second system is capable of occupying an idea only when it is in allegra position to check the development of pain emanating from it.. Lick him! Lick him! exclaimed Buller. lyrica. Her daughter having completed her education at the best boarding-school in effexor Philadelphia, and her son being about to graduate at Princeton, the mother had planned with her children a tour to Niagara and the lakes, returning by way of Boston.. It compels us to pursue the phentermine inner meaning of the dream in these productions.. Got a pencil? He produced the bit of cardboard; Ross fished up a chewed stump of lead pencil, took it in cold, stiff fingers, and disfigured the square with eccentric soma scribblings.. All manifestations disappeared as a result of a lengthy sojourn in the country, bodily exercise, and the return fluoxetine of physical strength after the termination of the period of puberty.. She's just outside, meanderin' in the road--kinder shy, ye avandia know, at first.. His parents came home late and went to bed while calcium he was feigning sleep.. The track phentermine couldn't have been in better condition.. Let pretend we ain't here and he'll go away, zithromax breathed Abner.. And I had not been at work a year before I found I was living two lives, one real and one merely functional--for two sets of people, one my parish, whom I loved, lexapro and the other a vague public, for whom I did not care two straws...
alex said…
Then we will go into the lock and in a few minutes we shall be on the evista lake.. After considerable whispering between Jane and her mother, the former withdrew, and sent in by the Irish girl a waiter with a basket of soda biscuit, a lithium pitcher of water, and some glasses.. But on the diflucan first appearance of my double--whom I sent on this fatal Monday to the fifth meeting--he was the sixty-seventh man who entered the room.. Atrocious! she exclaimed. diovan. Let us, however, keep to the fact--this is the key to the theory of repression--that the second system is capable of occupying an idea only when it is in vicodin position to check the development of pain emanating from it.. Lick him! Lick him! exclaimed Buller. acyclovir. Her daughter having completed her education at the best boarding-school in diclofenac Philadelphia, and her son being about to graduate at Princeton, the mother had planned with her children a tour to Niagara and the lakes, returning by way of Boston.. It compels us to pursue the viagra inner meaning of the dream in these productions.. Got a pencil? He produced the bit of cardboard; Ross fished up a chewed stump of lead pencil, took it in cold, stiff fingers, and disfigured the square with eccentric phentermine scribblings.. All manifestations disappeared as a result of a lengthy sojourn in the country, bodily exercise, and the return allopurinol of physical strength after the termination of the period of puberty.. She's just outside, meanderin' in the road--kinder shy, ye celexa know, at first.. His parents came home late and went to bed while naprosyn he was feigning sleep.. The track heparin couldn't have been in better condition.. Let pretend we ain't here and he'll go away, calcium breathed Abner.. And I had not been at work a year before I found I was living two lives, one real and one merely functional--for two sets of people, one my parish, whom I loved, calcium and the other a vague public, for whom I did not care two straws...
alex said…
.. .. .. .. .. .. .. .. .. .. .. .. .. .. ...
alex said…
.. .. .. .. .. .. .. .. .. .. .. .. .. .. ...
Anonymous said…
does someone know how to make this work also with the server explorer in Visual Studio (previously asked by trevor d'arcy-evans).
BitStream said…
Just for reference, if you happen to come across this post and add the xml snippet required, you must make sure the version number in the snippet matches the version you have. As of this posting, Npgsql2 beta2 has a version of 1.98.2.0

Popular posts from this blog

Npgsql Tips: Using " in (...)" queries with parameters list and "any" operator

Hi, all! We have received some users questions about how to send a list of values to be used in queries using the "in" operator. Something like: select foo, bar from table where foo in (blah1, blah2, blah3); Npgsql supports array-like parameter values and the first idea to have this working would try to use it directly: NpgsqlCommand command = new NpgsqlCommand("select * from tablee where field_serial in (:parameterlist)", conn); ArrayList l = new ArrayList(); l.Add(5); l.Add(6); command.Parameters.Add(new NpgsqlParameter("parameterlist", NpgsqlDbType.Array | NpgsqlDbType.Integer)); command.Parameters[0].Value = l.ToArray(); NpgsqlDataReader dr = command.ExecuteReader(); but unfortunately this won't work as expected. Npgsql will send a query like this: select * from tablee where field_serial in ((array[5,6])::int4[]) And Postgresql will complain with the followin...

Fixed! LOG: unexpected EOF on client connection

Hi all! Since we implemented connection pool in Npgsql, we received some complaints about EOF log messages being generated on Postgresql logs when using Npgsql. This was caused by Npgsql not sending the proper terminate message to Postgresql on pooled connections when the application terminated or more specifically when the assembly was unloaded. This is a long time problem with Npgsql connection pool. I even talked about it in the past . Up to now, I had no idea about how to fix that as I wasn't able to close the connections in the pool. When I tried to put a finalizer in NpgsqlConnectorPool, which would be triggered when the assembly was unloaded, I received object already disposed exceptions when trying to send something to the stream. That's when I came up with the "excellent" idea of subclassing the networkstream class and override its Dispose method so that I could send the postgresql terminate message before it was disposed! :) It worked like a charm! ...

Npgsql 2.2.0 final release is out!

This is Npgsql 2.2.0 Final Release This release contains 249 commits since the last stable release. Includes bug fixes, improvements and new features. Update notice: If you have been using Npgsql 2.2.0-rc2, you don't need to update to this version. They are the same except for the Assembly version information. Major highlights Visual Studio DDEX support   Kenji Uno added support for DDEX. Now you can use Npgsql with Visual Studio data designer. This is a missing feature a lot of our users requested in the past. Kenji added a tutorial about how to use Npgsql with DDEX. You can find it here: https://github.com/npgsql/Npgsql/wiki/Visual-Studio-Design-Time-Support---DDEX-Provider#install-npgsqlddexprovidervsix   Entity Framework   David Karlaš added support for EFMigration and Database creation in EF6+. Now it is possible to start Code First projects without needing to create a database upfront. EntityFramework and Npgsql will take care of it. E...