Tuesday, June 21, 2011

Mono Firebird Example updated for Mono 2.6/2.10.x release (#ubuntu / #debian)

Mono Firebird Example updated for Mono 2.6 release

First I hope you have Firebird 2.5 already installed with examples :)

Second Install Monodevelop and Mono
In my case was something like this on ubuntu
sudo apt-get install  mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol  monodoc-gtk2.0-manual 

Also on Debian you can use mono 2.10.x by using experimental repository (after you add it in /etc/apt/sources.list)

sudo apt-get -t experimental install  mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol  monodoc-gtk2.0-manual 

You must download the .Net Provider 2.6.5 for mono binary version NETProvider-2.6.5-MONO_LINUX.7z
Extract it somewhere in the project dir where you want to build it

Create an new C# Console Project
Then add the Firebird .net assembly to the test project
References-> Edit References -> .Net Assembly
browse to the FirebirdSql.Data.FirebirdClient.dll that you downloaded before (and extracted)
then click Add button



Fill the Main.cs this way and Build Solution (Also add System.Data references)

using System;
using System.Data;
using FirebirdSql.Data.FirebirdClient;
namespace FirebirdTest
{
class MainClass
{
public static void Main(string[] args) {
string connectionString =
"Database=/var/lib/firebird/2.5/data/employee.fdb;" +
"User=SYSDBA;" + "Password=masterkey;" +
"Dialect=3;character set=NONE;" + "Server=localhost";
IDbConnection dbcon = new FbConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql = "select * from employee";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
object dataValue = reader.GetValue(0);
string sValue = dataValue.ToString();
Console.WriteLine("Value: " + sValue);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}}
view raw Main.cs hosted with ❤ by GitHub


Then click run after the solution is build and the result should be like this

2 comments:

aicl said...

hi,
links to old.nabble.com do not work !

Popa Adrian Marius said...

Thanks is work in progress and i will update the guide to mono 2.10.x