[Mono-list] Npgsql error
Fabian Salamanca Dominguez
fsalaman at gmail.com
Thu Aug 4 13:35:59 EDT 2005
Hi
I tried to compile a simple C# program and access a Postgresql DB but I got
this error in runtime (it compiled with no errors) :
[fsalaman at ipdserver Mono]$ mcs dbaccess.cs -r:Npgsql.dll -r:System.Data.dll
[fsalaman at ipdserver Mono]$ mono dbaccess.exe
Unhandled Exception: System.InvalidCastException: Cannot cast from source
type to destination type.
in <0x000e1> dbAccess:Main (System.String[] args)
****************
This is the code:
using System;
using System.Data;
using Npgsql;
public class dbAccess
{
public static void Main(string[] args)
{
string connectionString =
"Server=localhost;" +
"Database=opennms;" +
"User ID=opennms;" +
"Password=opennms;";
IDbConnection dbcon;
dbcon = new NpgsqlConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql =
"SELECT operatingsystem, nodeid " +
"FROM assets";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string operatingsystem = (string) reader["operatingsystem"];
string nodeid = (string) reader["nodeid"];
Console.WriteLine("OS: " +
operatingsystem + " " + nodeid);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
What am I doing wrong?
Thanks!!!
--
Fabian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20050804/7a416352/attachment-0002.html
More information about the Mono-list
mailing list