[Mono-list] Problems with postgres.
Angel Reyes
areyes@agconsultoria.com.mx
Wed, 19 Nov 2003 12:06:05 -0600
--=-s/biwNRjE27Mx15IWcqb
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hola Roberto-
I've to modify the Npgsql example from
http://go-mono.com/postgresql.html , check this code:
================ postgresTest.cs ==============
using System;
using System.Data;
using Npgsql;
public class Test
{
public static void Main(string[] args)
{
string connectionString =
"Server=127.0.0.1;" +
"Database=DBF;" +
"User ID=angel;" +
"Password=********;";
//IDbConnection dbcon;
NpgsqlConnection dbcon = new NpgsqlConnection(connectionString);
dbcon.Open();
//dbcon = new NpgsqlConnection(connectionString);
IDbCommand dbcmd = dbcon.CreateCommand();
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT codemp, cnombre " +
"FROM empresa";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
String FirstName = (String)reader["codemp"];
String LastName = (String)reader["cnombre"];
Console.WriteLine("Name: " +
FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
=========================================
Compiling...
mcs -r Npgsql.dll -r System.Data.dll postgresTest.cs
Check Npgsql.dll is located in the same directory as System.Data.dll,
usually /usr/lib.
On Tue, 2003-11-18 at 19:18, Roberto Jimeno wrote:
> Hi there!
>
> Tim, Rodrigo, Daniel, Rafael or someone willing to
> help a mono/sql newbie here.
>
> I'm using Mono 0.28 installed from an RPM file (and I
> have reasons to stick to the RPM file rather than
> using CVS)
>
> I'm writing some C# code which requires to select some
> information from a bunch of already-filled tables on a
> postgres database.
>
> I tried to use Mono.Data.PostgreSQL unsuccessfully as
> well as Npgsql (more details on this at the bottom of
> the message). Now I don't know what to do: Should I
> keep on trying with either of those data providers?
> Should I try to use ByteFX with postgres? Where can I
> find more information about it?
>
>
> Thanks in advance for helping me.
>
>
>
> Details on the tests and failures with both data
> providers:
>
> >From http://go-mono.com/postgresql.html I copied
> verbatim the examples for Mono.Data.PostgreSqlClient
> and Npgsql named them
> TestExample.Mono.Data.PostgreSqlClient.cs and
> TestExample.Npgsql.cs respectively, and then followed
> the instructions found there, in order to compile and
> use the examples:
>
> When I tried to compile the one using PostgreSqlClient
> , it failed with "Cannot find type `PgConnection'"
>
> Afterwards, I tried to compile the one using Npgsql,
> which also failed, this time indicating "Use of
> unassigned local variable `dbcon'" on line 15.
>
> >From somewhere (I can't remember where, but the source
> file is also attached) I copied another test example
> which compiles on my system, although when I attempt
> to run the .exe file using mono, it complains about an
> unhandled exception ("A null value was found where an
> object instance was required")
>
>
> The command lines Im using to build (or attempt to
> build) the test examples are as follows:
>
> $mcs TestExample.Mono.Data.PostgreSqlClient.cs -r
> System.Data.dll -r Mono.Data.PostgreSqlClient.dll
>
> $mcs TestExample.Npgsql.cs -r System.Data.dll -r
> Npgsql.dll
>
> $mcs OtherTestExample.cs -r System.Data.dll -r
> Mono.Data.PostgreSqlClient.dll
>
>
> =====
> Roberto Jimeno
>
> __________________________________
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
> http://antispam.yahoo.com/whatsnewfree
--
Angel
http://bukox.tripod.com
--=-s/biwNRjE27Mx15IWcqb
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.0.9">
</HEAD>
<BODY>
Hola Roberto-<BR>
<BR>
I've to modify the Npgsql example from <A HREF="http://go-mono.com/postgresql.html"><I><U>http://go-mono.com/postgresql.html</U></I></A> , check this code:<BR>
<BR>
================ postgresTest.cs ==============<BR>
using System;<BR>
using System.Data;<BR>
using Npgsql;<BR>
<BR>
public class Test <BR>
{<BR>
public static void Main(string[] args)<BR>
{<BR>
string connectionString = <BR>
"Server=127.0.0.1;" +<BR>
"Database=DBF;" +<BR>
"User ID=angel;" +<BR>
"Password=********;";<BR>
//IDbConnection dbcon;<BR>
NpgsqlConnection dbcon = new NpgsqlConnection(connectionString);<BR>
dbcon.Open();<BR>
//dbcon = new NpgsqlConnection(connectionString);<BR>
IDbCommand dbcmd = dbcon.CreateCommand();<BR>
// requires a table to be created named employee<BR>
// with columns firstname and lastname<BR>
// such as,<BR>
// CREATE TABLE employee (<BR>
// firstname varchar(32),<BR>
// lastname varchar(32));<BR>
string sql = <BR>
"SELECT codemp, cnombre " +<BR>
"FROM empresa";<BR>
dbcmd.CommandText = sql;<BR>
IDataReader reader = dbcmd.ExecuteReader();<BR>
while(reader.Read()) {<BR>
String FirstName = (String)reader["codemp"];<BR>
String LastName = (String)reader["cnombre"];<BR>
Console.WriteLine("Name: " + <BR>
FirstName + " " + LastName);<BR>
}<BR>
// clean up<BR>
reader.Close();<BR>
reader = null;<BR>
dbcmd.Dispose();<BR>
dbcmd = null;<BR>
dbcon.Close();<BR>
dbcon = null;<BR>
}<BR>
}<BR>
<BR>
=========================================<BR>
<A HREF="mailto:mono-list@lists.ximian.com"></A><BR>
Compiling...<BR>
mcs -r Npgsql.dll -r System.Data.dll postgresTest.cs<BR>
<BR>
Check Npgsql.dll is located in the same directory as System.Data.dll, usually /usr/lib.<BR>
<BR>
<BR>
<BR>
<BR>
On Tue, 2003-11-18 at 19:18, Roberto Jimeno wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373"><I>Hi there!
Tim, Rodrigo, Daniel, Rafael or someone willing to
help a mono/sql newbie here.
I'm using Mono 0.28 installed from an RPM file (and I
have reasons to stick to the RPM file rather than
using CVS)
I'm writing some C# code which requires to select some
information from a bunch of already-filled tables on a
postgres database.
I tried to use Mono.Data.PostgreSQL unsuccessfully as
well as Npgsql (more details on this at the bottom of
the message). Now I don't know what to do: Should I
keep on trying with either of those data providers?
Should I try to use ByteFX with postgres? Where can I
find more information about it?
Thanks in advance for helping me.
Details on the tests and failures with both data
providers:
>From </FONT><A HREF="http://go-mono.com/postgresql.html"><U>http://go-mono.com/postgresql.html</U></A><FONT COLOR="#737373"> I copied
verbatim the examples for Mono.Data.PostgreSqlClient
and Npgsql named them
TestExample.Mono.Data.PostgreSqlClient.cs and
TestExample.Npgsql.cs respectively, and then followed
the instructions found there, in order to compile and
use the examples:
When I tried to compile the one using PostgreSqlClient
, it failed with "Cannot find type `PgConnection'"
Afterwards, I tried to compile the one using Npgsql,
which also failed, this time indicating "Use of
unassigned local variable `dbcon'" on line 15.
>From somewhere (I can't remember where, but the source
file is also attached) I copied another test example
which compiles on my system, although when I attempt
to run the .exe file using mono, it complains about an
unhandled exception ("A null value was found where an
object instance was required")
The command lines Im using to build (or attempt to
build) the test examples are as follows:
$mcs TestExample.Mono.Data.PostgreSqlClient.cs -r
System.Data.dll -r Mono.Data.PostgreSqlClient.dll
$mcs TestExample.Npgsql.cs -r System.Data.dll -r
Npgsql.dll
$mcs OtherTestExample.cs -r System.Data.dll -r
Mono.Data.PostgreSqlClient.dll
=====
Roberto Jimeno
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard</FONT>
<A HREF="http://antispam.yahoo.com/whatsnewfree"><U>http://antispam.yahoo.com/whatsnewfree</U></I></A></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>--
Angel
http://bukox.tripod.com</PRE>
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>
--=-s/biwNRjE27Mx15IWcqb--