oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Mono Unveiled

by Brian Jepson

GNOME and .NET are getting together. According to today's announcement, Ximian is working on Mono, an implementation of the .NET CLI. Although the .NET CLI is currently a small subset of the entire .NET framework, you can expect Mono to go beyond the CLI, as it will likely implement much of the framework in the near future.

As you know, Windows programmers are fond of creating large databases and linking them to user interfaces. Fortunately, GNOME has ways of doing this. Under Mono, the Windows Forms API will be implemented using the GTK+ user interface toolkit, and ADO.NET will be implemented using GNOME-DB.

Since Mono isn't complete now, all I can do is dream about this kind of stuff. So I decided to write similar programs in GNOME and .NET and see where the differences are.

Connecting to the Database

GNOME-DB and ADO.NET both rely on data providers, adapters between the client API and a back-end database. Since each database has a different API, a data provider maps that API to the GNOME-DB or ADO.NET API. Here's how to connect to SQL Server's pubs database using ADO.NET:

  /* This connection string specifies:
   *   Provider: OLE DB SQL Server provider
   *   Server:   Local machine
   *   Database: pubs
   *   User:     sa
   *   Password: (blank)
  String cs = "provider=sqloledb;server= 
  /* Make the connection. */
  OleDbConnection cnc = new OleDbConnection(cs);

Related article:

GNOME's Miguel de Icaza on .NET

This next listing shows you how to connect to PostgreSQL using GNOME-DB. Notice that you have to take a brief drink from the CORBA well to create a connection. This is because GNOME uses a high-performance CORBA implementation called ORBit (GNOME also provides the OAF Library to make it easy to deal with CORBA).

  GdaConnection* cnc;
  gchar *pg_provider = "OAFIID:GNOME_GDA_Provider_Postgres_ConnectionFactory";

  /* Initialize GNOME-DB */
  gnome_db_init("db_connect", "0.1", argc, argv);

  /* Use the ORB to create a new connection object. */
  cnc = gda_connection_new(gda_corba_get_orb());

  /* Make a connection to the database. */
  gda_connection_set_provider(cnc, pg_provider);
  gda_connection_open(cnc, "DATABASE=bjepson", "bjepson", "");

Pages: 1, 2

Next Pagearrow