Wednesday, December 14, 2011

Npgsql2 source code mirror is now available on github

Hello, all!

Npgsql2 source code hosted on pgfoundry is now mirrored on github:

What does this mean to developers and users?

  • You have another way of access to latest Npgsql2 code through github interface
  • I hope it will be easier to developers and users to provide patches. You can make forks and pull requests.
Please, if you weren't being able to access Npgsql2 source code because of cvs, please give it a try on this new interface and let me know if you have any problems.

Thanks github for providing this service to open source community. 

Sunday, December 04, 2011

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! Now, Npgsql doesn't produce EOF log messages anymore.
The current implementation isn't very beautiful, as it is a simple callback to NpgsqlConnector.Close() method, but it works ok and there is no need to manage with any other finalizer.

Next Npgsql version will have this fix and finally we will get rid of this strange log message.

Saturday, May 14, 2011

Npgsql Design time support preview available for download!

UPDATE2: For some reason, Blogger lost the original post. I had to republish it.

UPDATE: Jerónimo told me that you must use the Npgsql version which is inside the zip file in order to make it work.

After so much time (more than I wanted it to take) Npgsql finally has a initial design time support for Visual Studio!

This work was done by Jerónimo Milea. Jerónimo let me know he was working on DDEX support on this thread after I said I was working on DDEX support for Npgsql.

He sent me his working copy and I started to play with it. Note that as a preview version many things may not work ok and we wanted you to provide us feedback so we can fix any bugs.

You can download the project file from our downloads page.

Design time support is provided as a zip file containing support code as well as a copy of Npgsql project file. So, everything you need to start working with design time support is already packaged for you.

When you unzip the file, you will have three folders and a project file. Open up this project file in Visual Studio 2010.

There are three projects. The Npgsql.Provider project is there for historical reasons, Jerónimo told me. We will clean it up in another release. The main project is the Npgsql.Provider2. Set it up as your startup project. Right Click -> Set up as Startup Project.

After that, tell Visual Studio to build all projects. After everything is compiled ok, there are still some other steps to be done:

  1. Install Npgsql.dll and Mono.Security.dll to GAC. 
  2. Add Npgsql as a provider factory in machine.config

Install Npgsql.dll and Mono.Security.dll to GAC
    Go to the Npgsql2\bin\debug4\ folder and add Npgsql.dll and Mono.Security.dll to GAC:
    gacutil -i Npgsql.dll
    gacutil -i Mono.Security.dll

    Note that you will need to start a Visual Studio Command Prompt so command line tools are available to you. This shortcut is inside Visual Studio 2010 programs folder in the Visual Studio Tools subfolder.

Add Npgsql as a provider factory in machine.config

    In the machine.config file, located at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config you have to add following line: 

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

    This line goes inside the DbProviderFactories section.

Playing with Design Time support project

    After config Npgsql in gac and machine.config, it's time to run the project.

    As this project will work inside VS.Net, you will need to debug VS.Net itself in order to have the project running inside it. In order to do that, you have to specify as the debug target. To do that, open Npgsql.Designer2 project properties and in the Debug tab, check the value of "Start external program" edit text. It is set to the path of devenv.exe. Note that it is the path of (x86) Program Files folder. This is ok if you are using a 64-bits windows installation. If you are using a 32-bits install (as I do), you just have to remove the (x86) from the path and you are set.

    After setting everything up, you can hit F5 to start the project ( you specified Npgsql.Designer2 as your startup project, right?). A new VS.Net will show up and your first VS.Net will be attached to it in debug mode. Now, comes a very important step you have to make: Inside Npgsql.Designer2 folder, there is a file called NpgsqlProvider.gen.reg. You have to merge this file to your registry every time you start VS.Net to debug the project. This is needed because VS.Net as it is started by the project, has a command line option which makes it use an alternate registry tree which is cleaned up every time this is started. This reg file has the settings to register Npgsql.Designer inside VS.Net.

    That's it! If everything is ok, you may now create a new project or open an existing one and add a new datasource to it using Postgresql as the backend! This procedure is somewhat complex, but after it is done once, you only have to repeat the merge registry file part.

    Please, let me know if you have any problems setting this up. Also, please, send your comments and bug reports to our bug tracker:

    Again, thanks Jerónimo for all his help and for this excellent work.