Reputation: 864
I have a mainframe SP with below parameters
IN "APPLCD " "SYSIBM "."CHAR"
,
INOUT "CMCNAREA " "SYSIBM "."CHAR"
,
OUT "RETURNCD " "SYSIBM "."INTEGER"
,
OUT "MSG " "SYSIBM "."CHAR"
Using below connection string
<add name="name" connectionString="Driver={IBM DB2 ODBC DRIVER};Database=DBName;Hostname=IP;Port=port;Protocol=TCPIP;Uid=uid;Pwd=pwd;" providerName="System.Data.Odbc" />
I am assuming that parameter types and names not mapped correctly between C# and SP. Can somebody confirm below .NET code as I am going to execute it once I got server access.
var AD1107P_APPCD = command.CreateParameter();
AD1107P_APPCD.Direction = ParameterDirection.InputOutput;
**AD1107P_APPCD.DbType = DbType.String;**
AD1107P_APPCD.ParameterName = "AD1107P_APPCD";
AD1107P_APPCD.Size = 8;
AD1107P_APPCD.Value = samParm;
command.Parameters.Add(AD1107P_APPCD);
var AD1107P_COMMAREA = command.CreateParameter();
AD1107P_COMMAREA.Direction = ParameterDirection.InputOutput;
**AD1107P_COMMAREA.DbType = DbType.String;**
AD1107P_COMMAREA.ParameterName = "AD1107P_COMMAREA";
AD1107P_COMMAREA.Size = 200;
AD1107P_COMMAREA.Value = "OT";
command.Parameters.Add(AD1107P_COMMAREA);
var AD1107P_RC = command.CreateParameter();
AD1107P_RC.Direction = ParameterDirection.Output;
**AD1107P_RC.DbType = DbType.Int32;**
AD1107P_RC.ParameterName = "AD1107P_RC";
command.Parameters.Add(AD1107P_RC);
var AD1107P_MESSAGE = command.CreateParameter();
AD1107P_MESSAGE.Direction = ParameterDirection.Output;
AD1107P_MESSAGE.DbType = DbType.String;
AD1107P_MESSAGE.ParameterName = "AD1107P_MESSAGE";
AD1107P_MESSAGE.Size = 128;
command.Parameters.Add(AD1107P_MESSAGE);
Upvotes: 1
Views: 147
Reputation: 26
Jaish.
On the surface it looks like it's ok (not sure what the asterisks are).
However, if you're using Enterprise library 6 then none of that code is necessary.
You would want to configure your project to use a custom database using the Enterprise Library Configuration editor (in Visual Studio: right-click app.config or web.config/Edit configuration file v6).
Once you have your database provider configured the code would look something like this:
var db = new DatabaseProviderFactory().Create("the_name_you_gave_your_connection_string");
using (var cmd = db.GetStoredProcCommand("sp_name"))
{
db.DiscoverParameters(cmd);
// Set the parameter values either directly or through an IParameterMapper or an accessor.
// Here's an example of setting them directly:
cmd.Parameters["@P1"].Value = "some value";
// if you want to retrieve a DataSet:
using (var ds = db.ExecuteDataSet(cmd))
{
// ... do something with the returned data.
}
// If you just want to call the stored procedure:
db.ExecuteNonQuery(cmd);
}
Hope this helps,
Mike
Upvotes: 1