Building Informix Data- Driven Applications with.Net Sean R. Durity Manager of IT CornerCap...

Post on 18-Jan-2016

215 views 0 download

transcript

Building Informix Data-Building Informix Data-Driven Applications Driven Applications

with .Netwith .NetSean R. DuritySean R. Durity

Manager of ITManager of IT

CornerCap Investment CounselCornerCap Investment Counsel

Informix User Forum 2006

Washington, D.C. December 8-9, 2006

AgendaAgenda

• The IBM Informix ADO.Net Driver• ADO.Net Driver Basics (with

examples)• Building A Real Application (demo)• Q & A

The Informix ADO.Net DriverThe Informix ADO.Net Driver• Current version is Client SDK 2.90TC6• Now installed by default, must have .Net

framework 1st (works with either 1.1 or 2.0 framework)

• Namespace is IBM.Data.Informix - reference the library IBM.Data.Informix.dll

• Client SDK must be installed on any client that will use the driver (not self-contained in the .dll)

• Current documentation and examples are better than the previous ones; reference guide twice as long

• Objects are similar to Microsoft’s Sql* objects, but use “Ifx” prefix (IfxConnection, IfxCommand, etc.)

The Informix ADO.Net DriverThe Informix ADO.Net Driver

• Installation Issues– If you have the older driver (2.81), you should

either install into the same directory or remove the previous installation first. I could not get the two versions to peacefully co-exist.

– There is a stored procedure creation script that must be run once against the sysmaster database (as user ‘informix’). Otherwise, features like the DataAdapter wizard won’t connect. Script is $INFORMIXDIR/etc/cdotnet.sql on any client machine.

The Informix ADO.Net DriverThe Informix ADO.Net Driver

• New features in 2.90– Adds an IfxDataAdapter Configure Data

Adapter wizard– Adds new types including IfxDateTime,

IfxDecimal, IfxBlob, and IfxClob– Supports IPv6 protocol

The Informix ADO.Net Driver The Informix ADO.Net Driver BasicsBasics

• Connection String (getting a connection)– Semi-colon delimited list of attributes put into the

ConnectionString property of the IfxConnection objectstring ConnectionString = "Host=" + HOST + "; " +

"Service=" + SERVICENUM + "; " +"Server=" + SERVER + "; " +"Database=" + DATABASE + "; " +"User Id=" + USER + "; " +"Password=" + PASSWORD + "; ";

IfxConnection conn = new IfxConnection();conn.ConnectionString = ConnectionString;try { conn.Open();} catch (IfxException ex) { }

The Informix ADO.Net Driver The Informix ADO.Net Driver BasicsBasics

• Executing an insert, update or deleteIfxCommand cmd = new IfxCommand("insert into test

values (1, 2, ‘ABC’)",bconn.conn);cmd.CommandTimeout = 200; //seconds allowed for

command to finish, default is 30try {

int rows = cmd.ExecuteNonQuery();}catch (IfxException ex) {

Console.WriteLine("Error "+ex.Message);}

The Informix ADO.Net Driver The Informix ADO.Net Driver BasicsBasics

• Iterating through a SELECT’s result set one-timeIfxCommand cmd = new IfxCommand("select * from

test",bconn.conn);try {

IfxDataReader dr = cmd.ExecuteReader();while (dr.Read()) {

int a = dr.GetInt32(0);int b = Convert.ToInt32(dr["b"]);string c = (String)dr[2];

}dr.Close();

}catch (IfxException ex) {

Console.WriteLine("Error "+ex.Message);}

The Informix ADO.Net Driver The Informix ADO.Net Driver BasicsBasics

• Executing a Stored Procedure with “in” parameterIfxCommand cmd = new

IfxCommand("test_proc",bconn.conn);cmd.CommandType = CommandType.StoredProcedure;

//from System.Datacmd.Parameters.Add("in_parameter",2); //many ways

to create thesetry {

cmd.ExecuteScalar();}catch (IfxException ifxe) {

Console.WriteLine("Error "+ifxe.Message);}

ADO.Net 2.0ADO.Net 2.0

• MicroSoft fixed some underlying problems with its DataSet implementation (indexing). For large DataSets it can provide an order of magnitude performance improvement.– Note: the current Informix driver has its own

performance problems marshaling data from unmanaged to managed code. This also impacts the performance of large DataSets.

• Driver Availability from IBM – Open Beta just announced on www.iiug.org (12/02/2006)

Building Data ApplicationsBuilding Data Applications

• The DataSet– Microsoft’s disconnected database object

– like an in-memory database– One or more DataTables

• Each DataTable has a DataAdapter that interacts with the actual data store

– Can have primary keys, relations, etc.– Derived from ComponentModel, so it is

available in the Designer as graphical object

DataSet DiagramDataSet Diagram

Framework ConsiderationsFramework Considerations

• Concurrency checking– Could be implemented with interface and concurrency

column• Data binding – built-in can be flaky and not always bi-

directional• Data caching and lazy instantiation• Can’t make DataSets “global” and still use designer-

aided binding• How to define relations between objects• Null field checking; null objects allowed?• How to send data across the wire in n-tier

architecture• Open source .Net ORM frameworks (like nHibernate)

still emerging – no Informix-specific implementations that I have found

DevForce Framework from DevForce Framework from IdeaBladeIdeaBlade

DevForce EditionsDevForce Editions

• Express – Free version: ORM, UI DataBinding, RAD features, one-click deployment, royalty free

• Professional – support for stored procedures, databinding to 3rd party controls, multiple database connections, support

• Enterprise – Business Objects Server for n-tier deployment, disconnected or offline functionality, distributed transactions, web services objects (at CornerCap, we use this one)

DevForce Framework DevForce Framework ParticularsParticulars

• Uses OleDb for ORM (must run coledb script against sysmaster)

• No direct support for serial datatype, but I have Informix id generator code I am willing to share

• Includes its own object query language for writing queries (will probably move to LINQ. Pass-thru sql allowed.)

• Uses .Net Remoting for moving objects between tiers

• Concepts Guide is a must-read; other documentation, videos, and samples are good

DevForce – How Does it Work?DevForce – How Does it Work?

• ORM tool generates a DataRow class for each table/object (e.g., PlayerDataRow)

• Generates a descendent class from the DataRow (Player). This is where your custom code goes

• PersistenceManager class handles interactions with the database (no data adapters)

• BindingManagers handle UI binding• Business objects have relationships that allow

for “dot navigation” of properties from related objects

• Let’s go to the demo!

Q&A/DiscussionQ&A/Discussion

• Other Resources– DevForce framework (www.ideablade.com),

especially read the Concepts Guide!– DevForce user group (www.ibrunner.com)– Expert C# 2005 Business Objects, 2nd ed.

Rockford Lhotka (CSLA framework, if you want to do more of your own building. Many of the ideas are incorporated into DevForce)

– IdeaBlade contact – Lisa Martin (lisam@ideablade.com)

Building Informix Data-Building Informix Data-Driven Applications Driven Applications

with .Netwith .NetSean R. DuritySean R. Durity

sdurity@cornercap.comsdurity@cornercap.com

Informix User Forum 2006

Washington, D.C. December 8-9, 2006