Click to See Complete Forum and Search --> : How to connect AS400 using ADO .Net


Rohit Kukreti
February 11th, 2003, 09:49 AM
Hi NG,

I want to connect to a AS400 database using ADO .Net. But, i don't know how to go about. Can any one please help me?
or suggest me some sites.,

bye,
Rohit

N.B. Waiting for answers

CDC Dev
March 7th, 2003, 05:24 AM
to connect AS/400 with ADO 2.5 :

use the CWBX DLL
dim Sys as cwbx.as400System

set Sys = createobject("cwbx.as400System")
with Sys
.Define "server name"
.USERID = ""
.Password = ""
.PromptMode = cwbcoPromptNever
.Signon
end with

Maybe this code is operational with ADO.Net
Try it...

PMTinker
October 19th, 2004, 05:15 AM
Try this link
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?nav=false&forum=292&thread=30762&start=0&msRange=15&cat=19&message=4719418#4719418

somewhere around here is the answer

PMTinker
October 21st, 2004, 09:57 AM
oops link not working so here it is,

Dim objConnect As New OleDbConnection(ConfigurationSettings.AppSettings ("AS400")) 'opening a connection based on connection string
Dim objCmd As New OleDbCommand
objConnect.Open()
objCmd.Connection = objConnect
objCmd.CommandType = CommandType.Text
objCmd.CommandText = "{{CALL /QSYS.LIB/MOMSPGM.LIB/LISTMRCOM2.PGM(?,?)}}"
objCmd.Parameters.Add("&zzcomp", OleDbType.Char, 2).Value = "AU"
objCmd.Parameters.Add("&zzcom2", OleDbType.Char, 2).Value = "UK"
objCmd.ExecuteNonQuery()
objConnect.Close()

For it to work with parameters I had to upgrade the drivers using the OLEDB driver available in Client Access V5R3

PMTinker
November 1st, 2004, 12:21 PM
For anyone else that wants to know,
I discovered it is important to pad out your strings when calling a program

For example if the call has a parameter that you send with just 1 letter in but the pgm is expecting a 6 letter string then you have to add the the extra 5 spaces

so something like

objCmd.Parameters.Add("SCRNAM", OleDbType.Char, 6).Value = "N"

will be

objCmd.Parameters.Add("SCRNAM", OleDbType.Char, 6).Value = "N "

You cant say

objCmd.Parameters.Add("SCRNAM", OleDbType.Char, 1).Value = "N"

if that makes any sense to you

Taquelopa
March 1st, 2005, 07:42 PM
(Sorry for my english)

I'm created a WebService for conect to AS/400, and i had a problem.
When i have an error in AS/400 (RPGLE program) nobody will could execute nothing more. If the first call its running nobody will could execute nothing more too.
could someone helpme?

cwbx.AS400System as400 = new cwbx.AS400SystemClass();
cwbx.SystemNames sn = new cwbx.SystemNamesClass();
cwbx.Program program = new cwbx.ProgramClass(); //objeto programa
cwbx.StringConverter sc = new cwbx.StringConverterClass();
cwbx.ProgramParameters oParam = new cwbx.ProgramParametersClass();
try
{
string data = "Parm "; as400.Define( "system" ) as400.UserID = "user"; as400.Password = "pass"; as400.Signon();
program.system = as400;
oParam.Append("InputParam", cwbx.cwbrcParameterTypeEnum.cwbrcInput, length);
oParam.Append("OutputParam", cwbx.cwbrcParameterTypeEnum.cwbrcOutput, length); oParam["InputParam"].Value = data; program.LibraryName = "Library";
program.ProgramName = "Program";

program.Call( oParam );
string asResult = sc.FromBytes(oParam[OutputParam].Value);