我有这个代码;但是,当我尝试运行 Invoke 时,第一个命令将起作用并返回正确的值,但 command2 在 C# 代码下方给出了一个错误。为什么 C# 看不到 EPA 包,我需要做些什么来修复它?
对此的任何帮助将不胜感激。
我试图在 PL/SQL 中调用的函数的签名是
FUNCTION NotificationGetNextID return integer;
其他潜在的重要信息:我正在使用此 DLL 访问数据库http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html
//todo set all returns to void so that no one can see internal structure of db
internal static class Data
{
private const String User = "xxx";
private const String Pass = "xxx";
private const String Source = "xxx";
private const String DateFormat = "dd/MMM/yyyy";
public static DatabasePackage DatabasePackageFactory(DatabasePackageType T)
{
switch (T)
{
case DatabasePackageType.EPA:
return new EPA();
default:
return null;
}
}
private class EPA : DatabasePackage
{
OracleConnection Conn;
public EPA()
{
Conn = new OracleConnection();
Conn.ConnectionString += "User Id=" + User + ";";
Conn.ConnectionString += "Password=" + Pass + ";";
Conn.ConnectionString += "Data Source=" + Source + ";";
Conn.Open();
}
public object Invoke(String identifier, params String [] args)
{
//if you remove the commented out lines the code will not work, however now it works perfectly
var Command = Conn.CreateCommand();
//var Command2 = Conn.CreateCommand();
//Command2.CommandType = CommandType.StoredProcedure;
Command.CommandType = CommandType.Text;
Command.CommandText = "select EPA.NotificationGetNextID from dual";// + identifier + parameters;
//Command2.CommandText = "EPA.NotificationGetNextID";
//var reader2 = ((Command2.ExecuteNonQuery()));
var reader = ((Command.ExecuteReader()));
reader.Read();
return reader[0];
}
public void Dispose()
{
Conn.Close();
}
}
}
internal interface DatabasePackage : IDisposable
{
object Invoke(String identifier, params String[] args);
}
internal enum DatabasePackageType
{
EPA
}
错误 :
Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
PLS-00221: 'NOTIFICATIONGETNEXTID' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at EPA.Data.EPA.Invoke(String identifier, String[] args)
at EPA.ElectronicPriceAgreement.CompanyCreate()
打算如何使用
using (DatabasePackage dbp = Data.DatabasePackageFactory(DatabasePackageType.EPA))
{
return dbp.Invoke("NotificationGetNextId");
//return dbp.Invoke("CompanyCreate","key","description","","","","");
//return result;
}