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

UUID datatype and COPY IN/OUT support added to cvs

Hi all! It was just added support to uuid datatype in cvs head. This type will be available in next Postgresql release 8.3. Thanks to David Bachmann for his patch! You can get more info about this patch in this mailing list post . Also was added support for copy in and copy out operations. Now, users can provide streams which can be copied directly to and from Postgresql tables! Thanks to Kalle Hallivuori for providing a patch! Thanks to Truviso for giving support to Kalle. More info about that including a demo and ready to use compiled Npgsql.dll versions can be found here . That's it! As soon as we get more features added, I will post info about them here. Stay tuned! :)

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

Stream seek error

Hi all! Since Npgsql RC1, we started to receive some error reports about problems when closing connections. The typical stack trace looked like this: System.NotSupportedException : This stream does not support seek operations. at System.Net.Sockets.NetworkStream.Seek(Int64 offset, SeekOrigin origin) at System.IO.BufferedStream.FlushRead() at System.IO.BufferedStream.WriteByte(Byte value) − at Npgsql.NpgsqlQuery.WriteToStream(Stream outputStream) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlQuery.cs:line 62 − at Npgsql.NpgsqlReadyState.QueryEnum(NpgsqlConnector context, NpgsqlCommand command) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlReadyState.cs:line 64 − at Npgsql.NpgsqlConnector.ReleasePlansPortals() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlConnector.cs:line 373 − at Npgsql.NpgsqlConnectorPool.UngetPooledConnector(NpgsqlConnection Connection, NpgsqlConnector Connector) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlConnectorPool.cs:line 541 − at Npgsql.NpgsqlConnectorPool.ReleasePooledConnector(NpgsqlConn