当我尝试从我的 C# 代码调用 DB2 存储过程时,我收到以下错误消息:
错误 [42601] [IBM][CLI Driver][DB2/NT64] SQL0104N 在“get_profile_internet”之后发现了意外的标记“END-OF-STATEMENT”。预期的标记可能包括:“JOIN”。SQLSTATE=42601
我究竟做错了什么?
这是 DB2 - 存储过程代码
create procedure db2admin.pr_get_profile_internet (
IN p_profile_internet_id INT
)
BEGIN
DELCARE c_profile_internet CURSOR WITH RETURN TO CLIENT FOR
SELECT *
FROM profile_internet
WHERE profile_internet_id = p_profile_internet_id;
OPEN c_profile_internet;
END;
这是我的 C# 代码
public CDataResult<DataSet> GetProfileInternet() {
string v_connection_string = General.GetDBConnection();
CDataResult<DataSet> v_result = new CDataResult<DataSet>();
OdbcConnection v_connection = new OdbcConnection(v_connection_string);
try {
// Open Connection
v_connection.Open();
OdbcCommand cmd = new OdbcCommand("db2admin.pr_get_profile_internet", v_connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_profile_internet_id", OdbcType.Int);
cmd.Parameters["p_profile_internet_id"].Value = this.ProfileInternetId;
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
DataSet ds = new DataSet("GetProfileInternet");
da.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count > 0) {
v_result.ErrorOccured = false;
v_result.ErrorMessageEn = "";
} else {
v_result.ErrorOccured = true;
v_result.ErrorMessageEn = "Error! User code is not valid.";
}
} catch (Exception ex) {
v_result.ErrorOccured = true;
v_result.ErrorMessageEn = "DB error: CProfileInternet->GetProfileInternet()";
v_result.ErrorException = ex.Message + '\n' + ex.InnerException;
} finally {
if (v_connection != null) {
v_connection.Close();
}
}
return v_result;
}
这是最新的 C# 代码版本:
public CDataResult<DataSet> GetProfileInternet()
{
string v_connection_string = General.GetDBConnection();
CDataResult<DataSet> v_result = new CDataResult<DataSet>();
OdbcConnection v_connection = new OdbcConnection(v_connection_string);
try
{
// Open Connection
v_connection.Open();
OdbcCommand cmd = new OdbcCommand("call db2admin.pr_get_profile_internet", v_connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_profile_internet_id", OdbcType.Int);
cmd.Parameters["p_profile_internet_id"].Direction = ParameterDirection.Input;
cmd.Parameters["p_profile_internet_id"].Value = this.ProfileInternetId;
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
DataSet ds = new DataSet("GetProfileInternet");
da.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
v_result.ErrorOccured = false;
v_result.ErrorMessageEn = "";
}
else
{
v_result.ErrorOccured = true;
v_result.ErrorMessageEn = "Error! User code is not valid.";
}
}
catch (Exception ex)
{
v_result.ErrorOccured = true;
v_result.ErrorMessageEn = "DB error: CProfileInternet->GetProfileInternet()";
v_result.ErrorException = ex.Message + '\n' + ex.InnerException;
}
finally
{
if (v_connection != null)
{
v_connection.Close();
}
}
return v_result;
}
这是我的 DB2 存储过程代码:
create procedure db2admin.pr_get_profile_internet
( IN p_profile_internet_id int ) 开始
Declare c_profile_internet CURSOR WITH RETURN TO CLIENT FOR
Select *
From db2admin.profile_internet
Where profile_internet_id = p_profile_internet_id;
Open c_profile_internet;
结尾;
这是我的表结构
create table profile_internet
(
profile_internet_id int not null,
code_client varchar(30) not null,
prenom varchar(100) not null,
nom varchar(100) not null,
adresse varchar(100) not null,
appartement varchar(100) null,
ville varchar(100) not null,
code_postal varchar(30) not null,
code_province varchar(10) not null,
telephone_domicile varchar(30) null,
telephone_mobile varchar(30) null,
telephone_bureau varchar(30) null,
extension_bureau varchar(10) null,
date_de_naissance date null,
langue varchar(1) not null,
courriel varchar(100) null,
profil_actif smallint not null,
date_creation timestamp not null,
creer_par varchar(30) not null,
date_modification timestamp not null,
modifier_par varchar(30) not null,
primary key (profile_internet_id)
)
;
CREATE UNIQUE INDEX idx_profile_internet_code_client ON profile_internet (code_client);
CREATE UNIQUE INDEX idx_profile_internet_courriel ON profile_internet (courriel);
我应该怎么做才能避免收到以下错误消息:
错误 [42884] [IBM][CLI 驱动程序][DB2/NT64] SQL0440N 未找到类型为“PROCEDURE”的名为“DB2ADMIN.PR_GET_PROFILE_INTERNET”且具有兼容参数的授权例程。SQLSTATE=42884