Thread: Installing the Npgsql provider for .Net

Installing the Npgsql provider for .Net

From
"Rob Richardson"
Date:
Greetings!
 
I am trying to learn how to use ADO.Net to access a PostGRESQL database through C#, using MS Visual Studio 2008 on a Windows XP Pro box.  At first, I was using the PgOldDb provider for .Net, but it seems that that provider is not complete.  It did not work for me.  I switched to ODBC and was able to perform the update operations I spent more than a day struggling with.  I would still like to use OLE DB instead of ODBC, as I understand that it is faster and more compatible with the .Net architecture.  So I tried the Npgsql provider.  I was dismayed to see that there are no installation instructions on the PGFoundry download page, but a Google search turned up a user's manual.  According to that, all I had to do was to put the npgsql.dll file into a known location, and if I wanted IntelliSense to work, I had to put into the GAC as well.  So I did.  But when I tried to run an application using it, an exception was thrown complaining that it could not find file or assembly Mono.Security. 
 
Do I have the wrong file?  I loaded the .Net 2.0 version (or so I thought).  Do I need another file?  Should I use a different provider entirely? 
 
Thank you very much.
 
RobR
 

Re: Installing the Npgsql provider for .Net

From
"Francisco Figueiredo Jr."
Date:
On Tue, Jan 6, 2009 at 5:38 PM, Rob Richardson
<Rob.Richardson@rad-con.com> wrote:
> Greetings!
>

Hi, Rob!

You can find the manual in the download file which has a section about
how to install and use Npgsql.

Also, you can find the user manual online at:
http://manual.npgsql.org

You will need to add the file Mono.Security.dll into the GAC as
Npgsql.dll depends on it.
This file is also found in the downloaded file. Maybe you got one for
Mono which already contains the Mono.Security.dll assembly.

If you read the manual and still have doubts, please let us know.

I hope it helps.


--
Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://fxjr.blogspot.com
http://www.npgsql.org

Generic provider for .Net

From
"Rob Richardson"
Date:
My stumbling through the wilds of .Net, ADO.Net and PostGRESQL continues...
 
I left out a critical requirement from my discussion of .Net providers:  They must be compatible with some generic data type inside a .Net application.  The most that is allowed to change is a connection string.  If I use ODBC, I can access the database through OdbcConnection and its related classes.  All I have to do to change from PostGRESQL to SQL Server is to change from a DSN that refers to a PostGRESQL database to a DSN that refers to a SQL Server database.  When I was trying to get the PgOleDb provider to work, I was using the OleDbConnectioni class and its relatives with this connection string:
 
"Provider=PostgreSQL OLE DB Provider;Data Source=localhost;location=Great_Lakes_10_09;User ID=caps;Password=asdlkjqp" 
 
Somewhere in the depths of the registry, "PostgreSQL OLE DB Provider" is associated with the PgOleDb provider.  If I want to connect to a SQL Server database, I presume that I would be just change the name of the provider in this string to another name that is associated in the registry with a SQL Server provider.  I need a PostGRESQL provider that can be used through an OleDbConnection object just by using a connection string like:
 
"Provider=Some PostgreSQL Provider That Actually Works;Data Source=localhost;location=Great_Lakes_10_09;User ID=caps;Password=asdlkjqp" 
 
All of this is because the first thing a user sees when he starts our application is a dialog box in which he selects a database.  An ini file contains the list of available names, and each name is associated with a connection string.  When the user selects a name from a listbox, the connection string is read from the ini file.  So the only thing I can change once the application is built is the connection string.  The code has to work for PostGRESQL, SQL Server, and any other reasonably popular database system.  We can't have one version of the code built for PostGRESQL and another for SQL Server.  Therefore, unless there's some other way of setting it up, I cannot use Npgsql because I cannot use an NpgsqlConnection object.
 
RobR
 
 

Re: Generic provider for .Net

From
"Francisco Figueiredo Jr."
Date:
On Tue, Jan 6, 2009 at 7:00 PM, Rob Richardson
<Rob.Richardson@rad-con.com> wrote:
> My stumbling through the wilds of .Net, ADO.Net and PostGRESQL continues...
>


With this requirement, I would suggest you to use dbproviderfactory
support of .Net

This is a sample link with informations about it:

http://msdn.microsoft.com/en-us/library/dd0w4a2z%28VS.80%29.aspx


http://www.davidhayden.com/blog/dave/archive/2007/10/08/CreatingDataAccessLayerUsingDbProviderFactoriesDbProviderFactory.aspx


A little googling can provide you with more examples.

Also, on Npgsql manual there is the entry you have to make to register
Npgsql as a dbproviderfactory.

Also note that Npgsql supports sqlclient parameter style with the '@'
prefix to easy porting sql code from sqlserver to postgresql.

I hope it helps.


--
Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://fxjr.blogspot.com
http://www.npgsql.org