Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Building applications with Mono

0.00/5 (No votes)
6 Nov 2003 1  
Developing .NET cross platform applications using mono and IBM DB2

Introduction

MONO is an open source project started in 2001 under the coordination of Ximian, with the purpose of developing an open source, cross platform implementation of the .NET Framework. In this article, I will show the basics of building a distributed application using Mono. The application was written in C# on a RedHat 9 based system. It uses IBM DB2 as a database backend, the SAMPLE database that ships with DB2 and my IBM DB2 open source managed provider (included in the zip attached).

Description

This sample application is divided in 2 conceptual components: a server component accessible using .NET Remoting and a GUI application written in C# with GTK#. I chose to use this GUI toolkit because it is much more flexible and in some points much more mature than Windows.Forms and it has the big advantage of being truly cross platform. It also has the big advantage of having a really easy to use interface designer - GLADE. The interface is saved in XML based files that can be easily imported in the C# code using the Glade.XML class. As a matter of fact, you can even define the events your application will handle and specify the functions handling each event, inside GLADE.

For running on a Windows machine, GTK will need the cygwin environment.

The server component is a data source for the client application. To keep the example simple, it only returns an ArrayList which contains employee related data from the SAMPLE database. The client application will receive this ArrayList and will insert the employee data in a GtkTreeView (a flexible equivalent of more Windows.Forms components, a DataGrid in this particular case).

Building the code

  1. The IBM DB2 Managed Provider

    On Linux with Mono:

     mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                            -out:System.Data.Db2Client.dll  *.cs

    On Windows with Mono:

    mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                           -out:System.Data.Db2Client.dll  *.cs

    The managed provider can also be used with Microsoft .NET Framework implementation:

    csc -unsafe -target:library /d:OS_LINUX -r:System.Data.dll 
                          -out:System.Data.Db2Client.dll  *.cs
  2. The EmployeeManager component
    mcs -r:System.Data.dll -r:System.Data.Db2Client.dll remotable.cs
  3. The server component:
    mcs -r:System.Runtime.Remoting.dll -r:remotable.dll server.cs
  4. The client component:
    mcs -target:exe -resource:db2test.glade -r:remotable.dll 
       -r:System.Runtime.Remoting.dll -r:gtk-sharp.dll 
       -r:glade-sharp.dll -out:sample.exe sample.cs

Running the code

  1. Launch the server:
    [db2inst1@linux db2test]$ mono server.exe

    The server must be launched by a user that has DB2 rights.

  2. Launch the client:
    mono sample.exe

    If you encounter any problems running this sample or if you have any questions related to using mono, please don't hesitate to contact me at victor.vatamanescu @ hqsoftware . ro (spaces are used for spam protection).

Happy hacking!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here