3 When it comes to Mono and PostgreSQL, there are many ways
4 you can access your data.
8 There are many ADO.NET data providers for <a href="http://www.postgresql.org/">PostgreSQL</a>:
10 There are two providers created specifically for PostgreSQL included with Mono:
14 <li><a href="http://gborg.postgresql.org/project/npgsql/projdisplay.php">Npgsql</a>
16 <li>included with Mono</li>
18 <li>a .NET Managed Data Provider for PostgreSQL</li>
20 <li>Written in 100% C#</li>
22 <li>does not require a client library</li>
24 <li>works on Mono and Microsoft .NET</li>
26 <li>created by Francisco Figueiredo jr. and has many developers working on it
28 <li>works in the SQL# (command-line and GTK# GUI versions)</li>
30 <li>in namespace Npgsql and assembly Npgsql and is found in mcs
31 at mcs/class/Npgsql</li>
35 <li>Mono.Data.PostgreSqlClient (DEPRECATED)
38 <li>Deprecated in favor of Npgsql. No longer included in a release of Mono.</li>
43 <li><a href="http://sourceforge.net/projects/mysqlnet/">ByteFX.Data</a> has a provider for PostgreSQL too, but I do not know how well it works with Mono.</li>
45 <li>There is another .NET data provider for PostgreSQL named <a href="http://sourceforge.net/projects/pgsqlclient/">PgSqlClient</a>, but I do not know if it works with Mono.</li>
47 <li>If none of the above providers meet your needs. There is the ODBC and OLEDB providers included with Mono.</li>
49 <li>Bugs with Mono or the data provider should be reported
50 in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>. If you
51 do not have Bugzilla user account, it is free
53 create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
63 <li>Builds and Runs on both Microsoft .NET and Mono.</li>
64 <li>Works using SQL# (command-line and GTK# versions)</li>
65 <li>You can send insert, update, delete queries
\r
66 through NpgsqlCommand.ExecuteNonQuery() method.</li>
\r
67 <li>You can send queries like, select count(*) from table, select version()
\r
68 with NpgsqlCommand.ExecuteScalar() method.</li>
\r
69 <li>There is logging support. (Thanks Dave Page)
\r
70 To use it, place code like that in your program:</li>
\r
74 NpgsqlEventLog.Level = LogLevel.Debug; // LogLevel.
\r
75 NpgsqlEventLog.LogName = "NpgsqlTests.LogFile"; // LogFile.
\r
78 <li>You can use Npgsql with Mono (Thanks Kristis Makris). It is not working perfectly.</li>
\r
79 <li>There is a winforms test suite (Thanks Dave Page).</li>
\r
80 <li>Clearer code in NpgsqlConnection removing *magic* numbers and constants. (Thanks Kristis Makris)</li>
\r
81 <li>Better support of ODBC-like ConnectionString in NpgsqlConnection (Thanks Dave Page)</li>
\r
82 <li>Thanks Ulrich Sprick for all discussion and ideas.</li>
\r
90 <li>More testing and fixing bugs</li>
92 <li>Better error handling</li>
94 <li>More Data Types to use</li>
96 <li>Any features for Npgsql should be implemented in Npgsql's main cvs repository at
97 gborg.postgresql.org. Most bugs should be fixed in gborg.postgresql.org's cvs.
98 Only bugs neccessary for building and running of Npgsql on Mono can be done in Mono cvs,
99 but once applied they should be sent to Npgsql's mailing list
100 at gborg.postgresql.org for inclusion into cvs there. Whenever there is
101 a release of Npgsql (determined by Francisco Figueiredo jr. or a release
102 of Mono (determined by Miguel de Icaza), then the Npgsql source
103 in gborg.postgresql.org's cvs will be used to update the Npgsql source in
107 <li>Add any missing functionality to Npgsql. If this funtionality works on
108 .NET but not on Mono, implement the missing features or fix the bugs in Mono</li>
110 <li>Npgsql has been replaced Mono.Data.PostgreSqlClient as the provider of
111 choice to use. Mono.Data.PostgreSqlClient is deprecated and is no longer included in
112 Mono releases. Please use Npgsql for PostgreSQL data access.</li>
114 <li>Implement new features of PostgreSQL.</li>
122 <li>Have a working mono and mcs</li>
124 <li>Get <a href="http://gborg.postgresql.org/project/npgsql/projdisplay.php">Npgsql</a>
125 and make sure the binary assembly Npgsql.dll is installed in the same place that the
126 mono class libraries are located.
128 <li>C# Example for Npgsql:
136 public static void Main(string[] args)
138 string connectionString =
139 "Server=localhost;" +
141 "User ID=postgres;" +
144 dbcon = new NpgsqlConnection(connectionString);
146 IDbCommand dbcmd = dbcon.CreateCommand();
147 // requires a table to be created named employee
148 // with columns firstname and lastname
150 // CREATE TABLE employee (
151 // firstname varchar(32),
152 // lastname varchar(32));
154 "SELECT firstname, lastname " +
156 dbcmd.CommandText = sql;
157 IDataReader reader = dbcmd.ExecuteReader();
158 while(reader.Read()) {
159 string FirstName = (string) reader["firstname"];
160 string LastName = (string) reader["lastname"];
161 Console.WriteLine("Name: " +
162 FirstName + " " + LastName);
175 <li>Building C# Example:
177 <li>Save the example to a file, such as, TestExample.cs</li>
179 mcs TestExample.cs -r System.Data.dll \
184 <li>Running the Example:
192 ** Installation instructions for PostgreSQL DBMS:
196 * Read the PostgreSQL Installation Instructions
197 at \usr\doc\postgresql-x.x.x\html\installation.html
199 * Depending on your Unix system,
200 PostgreSQL maybe already installed, a database user 'postgres' created,
201 a linux user 'postgres' created and initdb ran. Or maybe not.
206 mkdir /usr/local/pgsql/data
207 chown postgres /usr/local/pgsql/data
209 initdb -D /usr/local/pgsql/data
210 postmaster -i -D /usr/local/pgsql/data
215 * Make sure you have a database user named postgres. It is best to install
216 the PostgreSQL DBMS under linux user postgres. When you run the postmaster,
217 run it under the user postgres as well. If this was not done, then you
218 will need to create a user named postgres for the System.Data tests.
220 * If you already installed PostgeSQL and you do not have a database
221 user named postgres, then you can create user postgres using psql:
225 create user postgres with password 'fun2db';
228 * The postmaster must be run with -i option.
230 * In the /usr/local/pgsql/data/pg_hba.conf file, you need
231 to have the AUTH_TYPE set to md5. You can read more on this at
232 /usr/doc/postgresql-7.2.1/html/client-authentication.html
234 PostgreSQL html docs are located. See the 2nd line below,
235 host 127.0.0.1 has an AUTH_TYPE md5 in pg_hba.conf.
238 # TYPE DATABASE IP_ADDRESS MASK AUTH_TYPE
241 host all 127.0.0.1 255.255.255.255 md5
244 * If you can not find your PostgreSQL documentation locally or you
245 did not install it, then you
246 can get it <a href="http://www.postgresql.org/idocs/">here</a>.
253 * Use the <a href="http://www.cygwin.com/">Cygwin</a> installer to
254 install the PostgreSQL DBMS. It is
255 found in the database category.
257 * <p>Read the file postgres-x.x.README at /usr/doc/Cygwin and read
258 the requirements to install PostgreSQL. Those requirements
259 are included with cygwin except cygipc. A default installtion
260 of cygwin does not install everything you will need, so on the
261 safe side, just include everything when installing cygwin.
263 * <p>The -x.x in postgres-x.x is the version of your PostgreSQL DBMS.
265 * <p>Once Cygwin has installed the PostgreSQL DBMS on your computer,
266 read the file FAQ_MSWIN which is available
267 in /usr/doc/postgres-x.x
269 * <p>Important notes from this file are:
272 <p><b>2.</b> - Install the latest <a href="http://www.neuro.gatech.edu/users/cwilson/cygutils/cygipc/index.html">CygIPC</a> package.
273 Cygwin includes a utility bunzip2 which can be used to unzip it. Now, change to
274 the root directory by
276 you can use "tar xvf cygipc.xxx.tar" to untar it
277 in the root directory in cygwin.
279 <p>The cygipc package contains the support to run ipc-daemon
281 to run before you can
282 run the PostgreSQL DBMS Server daemon (postmaster) or run
283 initdb which initializes the PostgreSQL database.
285 <p><b>3.</b> The Cygwin bin directory has to be placed in
286 the path before the Windows program directories,
287 for example, C:\cygwin\bin
289 <p><b>My own note.</b> In the Windows control panel, I set
290 the environment variables PATH to my cygwin /usr/local/bin,
291 /usr/bin, and /bin. I also set my LD_LIBRARY_PATH to
292 /usr/local/lib and /usr/lib. For example:
296 PATH=c:\cygwin\usr\local\bin;c:\cygwin\usr\bin;c:\cygwin\bin;
297 LD_LIBRARY_PATH=c:\cygwin\usr\local\lib;c:\cygwin\usr\lib;
300 <p><b>4.</b> Start the ipc-daemon that came with the cygipc
302 are two ways to do this: run it from the command line as:
308 <p>or you can set it up as a Windows service. See the
309 file cygrunsrv.README at /usr/doc/Cygwin on how to do this
310 for ipc-daemon and postmaster. Note the
311 troubleshooting section at the end of
312 the cygrunsrv.README file.
314 <p>To install ipc-daemon as a service,
319 ipc-daemon --install-as-service' (--remove-as-service)
329 <p>Read the installation.html file
330 at /usr/doc/postgresql-x.x/html/installation.html
332 <p>You will see in this file that you will need to
333 run the following commands:
337 mkdir /usr/local/pgsql/data
338 initdb -D /usr/local/pgsql/data
339 postmaster -D /usr/local/pgsql/data
344 <p>When you need to connect to the database,
345 you will need ipc-daemon and postmaster running. Start ipc-daemon
346 before any of the command above. If you restart your computer, you
347 need to start ipc-daemon and postmaster either manually or as a
350 <p>psql is a command-line PostgreSQL client tool to
351 enter and run SQL commands and queries.
353 <p>If there is no database user named postgres, create a user named
354 postgres with the following SQL command in the client tool psql:
359 create user postgres with password 'fun2db';
361 <p>The only reason I say this is so you can easily use the System.Data tests
362 without having to change the database, userid, etc.