Sunday, April 10, 2011

ASP.NET OLEDB – Informix

I will explain how ASP.NET can connect to Informix 11 database using Ole db Informix Provider by IBM

First download IBM Informix client sdk from IBM's site, for the current example I used version 3.5 - 32 bit for windows. The SDK must be installed on client's computer in order to get connection. After installation go to the Start Menu, all program, IBM Informix Client SDK and start SetNet 32 . Enter the server tab and set Informix database parameters. For my example the parameters were

IBM Informix server : ol_ids_1150_1
Hostname : 192.168.52.2
Protocol : olsoctcp
Service name : svc_ids_1150_1

Go to the Host tab
Host:192.168.1.2
User: Administrator

Click OK

Then go to C:\WINDOWS\system32\drivers\etc and open for edit the file “services”, at the end of the file, depending on the target's database, enter corresponding values.
For my example
svc_ids_1150_1 9088/tcp #ol_ids_1150_1
svc_drda 9089/tcp #svc_drda
save the file.

After that go to Start, All programs, IBM Informix Client SDK and open ILoginDemo. On File click run and enter appropriate values in the login form, use some existing database for the stores database entry. After hitting the ok button if no error appears than you are on the right way. If an error appear, then download the document called Informix error messages from internet, and look for the appeared error number.

If everything is fine then in the ASP.NET program type following

OleDbConnection conno = new OleDbConnection();
conno.ConnectionString = "Provider=Ifxoledbc;Data Source=databaseName@IBMInformixServer;User ID=user;Password=
conno.Open();
OleDbCommand commo = new OleDbCommand("select * from tabletest", conno);
commo.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(commo);
DataSet ds = new DataSet();
da.Fill(ds);
conno.Close();

The Dataset variable is filled with data from table tabletest

Good luck