1.调用返回OUT的存储过程
a.调用OUT字符串的存储过程;
csharp
#region 连接数据库
/// <summary>
/// 连接数据库
/// </summary>
/// <param name="connStatus"></param>
/// <param name="dbNode"></param>
/// <returns></returns>
public OracleConnection OpenConn(ref string connStatus, DBConnEntity dbNode)
{
try
{
if (conn == null || conn.State == ConnectionState.Closed)
{
//默认端口
if (dbNode.Port.Length < 1)
{
dbNode.Port = "1521";
}
conn = new OracleConnection();
//单节点
if (dbNode.IP == null || dbNode.IP2 == null)
{
conn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + dbNode.IP +
")(PORT=" + dbNode.Port + "))(CONNECT_DATA=(SERVICE_NAME=" + dbNode.DbSid + ")));" +
"Persist Security Info=True;User ID=" + dbNode.DbUser + ";Password=" + dbNode.DbPassW + ";";
}
else
{
//集群方式
string connStr = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =" + dbNode.IP + ")(PORT = " + dbNode.Port + "))(ADDRESS = (PROTOCOL = TCP)(HOST =" + dbNode.IP2 + ")(PORT = " + dbNode.Port + "))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =" + dbNode.DbSid + ")(FAILOVER_MODE=(TYPE = session)(METHOD = basic)(RETRIES = 180)(DELAY = 5) ) ));" +
"Persist Security Info=True;User ID=" + dbNode.DbUser + ";Password=" + dbNode.DbPassW + ";";
conn.ConnectionString = connStr;
}
conn.Open();
connStatus = "success";
}
else
{
connStatus = "success";
}
}
catch (Exception ex)
{
connStatus = ex.Message;
conn = null;
}
return conn;
}
//执行存储过程
public string execCancelJCErpProcedure(string targetId, DBConnEntity dbNode, ref string strNGPASS)
{
string returnMsg = "";
try
{
conn = OpenConn(ref strNGPASS, dbNode);
if (strNGPASS == "success")
{
using (conn)
{
using (OracleCommand cmd =
new OracleCommand("存储过程名称", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter locatorId =
new OracleParameter("locatorId", OracleDbType.Varchar2);
locatorId.Direction = ParameterDirection.Input;
locatorId.Value = targetId;
cmd.Parameters.Add(locatorId);
OracleParameter vs_msg =
new OracleParameter("resultOut", OracleDbType.Varchar2, 4000);//返回字符串时,需要设置字符串大小
vs_msg.Direction = ParameterDirection.Output;
cmd.Parameters.Add(vs_msg);
cmd.ExecuteNonQuery();
returnMsg = vs_msg.Value.ToString();
}
}
}
//连接数据库异常
else
{
strNGPASS = "NG";
returnMsg = strNGPASS; //连接数据库异常描述
}
}
catch (Exception ex)
{
strNGPASS = "NG";
returnMsg = ex.Message;
}
return returnMsg;
}
b.调用OUT 数值的存储过程;
csharp
public int execZLProcedure(string proceName, DBConnEntity dbNode,string model_name, ref string strNGPASS)
{
int batch_Id = 0;
try
{
conn = OpenConn(ref strNGPASS, dbNode);//连接数据库;
if (strNGPASS == "success")
{
using (conn)
{
using (OracleCommand cmd = new OracleCommand(proceName, conn)) //proceName存储过程名称
{
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter modelName = new OracleParameter("modelName", OracleDbType.Varchar2);
modelName.Direction = ParameterDirection.Input;
modelName.Value = model_name;
cmd.Parameters.Add(modelName);
OracleParameter batchId = new OracleParameter("batchId", OracleDbType.Int64);//
batchId.Direction = ParameterDirection.Output;
cmd.Parameters.Add(batchId);
cmd.ExecuteNonQuery();
batch_Id = int.Parse(batchId.Value.ToString());
strNGPASS = "OK";
}
}
}
else //连接数据库异常
{
strNGPASS = "NG";
}
}
catch (Exception ex)
{
strNGPASS = "NG";
}
return batch_Id;
}