这是我的存储过程,它在我的本地机器上运行良好,但在 PRODUCTION 上,它给了我上述错误:它抱怨 OUT 参数,最后一个:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_projects`(
IN userName varchar(20),
IN projectName text,
IN projectDescription text,
IN projectCurrency text,
IN projectBudget1 double,
IN projectBudget2 double,
IN projectEndDate DATETIME,
IN expectedDelivDate DATETIME,
IN projectMessageForBidder text,
OUT projectCode bigint)
BEGIN
DECLARE
l_project_code bigint;
insert into projects
(PROJECT_CODE,
SR_USER_NAME ,
PROJECT_NAME,
PROJECT_DESCRIPTION,
PROJECT_CURRENCY,
PROJECT_BUDGET1 ,
PROJECT_BUDGET2 ,
PROJECT_STATUS,
PROJECT_END_DATE,
PROJECT_PAID,
EXPECTED_DELIV_DATE,
PROJECT_MESSAGE_FOR_BIDDER,
PROJECT_CREATION_DATE,
PROJECT_UPDATE_DATE)
values
(
0,
userName,
projectName,
projectDescription,
projectCurrency,
projectBudget1,
projectBudget2,
'Active',
projectEndDate,
null,
expectedDelivDate,
projectMessageForBidder,
NOW(),
NOW());
SELECT LAST_INSERT_ID() into l_project_code;
SET projectCode = l_project_code;
END
下面是我的 C# 代码,用于设置参数:
MySqlCommand command = new MySqlCommand("insert_projects", dbcontroller.conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
// Add parameters for the insert_projects STORED PROC
command.Parameters.Add(new MySqlParameter("userName", SessionBag.Current.UserName));
command.Parameters["@userName"].Direction = System.Data.ParameterDirection.Input;
command.Parameters.Add(new MySqlParameter("projectCode", MySqlDbType.Int64));
command.Parameters["@projectCode"].Direction = System.Data.ParameterDirection.Output;
command.Parameters.Add(new MySqlParameter("projectName", model.projectName));
command.Parameters.Add(new MySqlParameter("projectDescription", model.projectDescription));
command.Parameters.Add(new MySqlParameter("projectCurrency", model.projectCurrency));
command.Parameters.Add(new MySqlParameter("projectBudget1", model.projectBudget1));
command.Parameters.Add(new MySqlParameter("projectBudget2", model.projectBudget2));
command.Parameters.Add(new MySqlParameter("projectEndDate", model.projectEndDate));
command.Parameters.Add(new MySqlParameter("expectedDelivDate", model.expectedDelivDate));
command.Parameters.Add(new MySqlParameter("projectMessageForBidder", model.projectMessageForBidder));
try
{
command.ExecuteNonQuery();
TempData["projectCode"] = (Int64)command.Parameters["?projectCode"].Value;
TempData["frompage"] = "AddProject";
dbcontroller.conn.Close();
return RedirectToAction("MyProjectsHeaderSR", "Projects");
}
为什么抱怨这个?我的本地机器工作正常。表“项目”包含一个名为 project_code 的字段,该字段设置为 BIGINT 自动增量......其余字段是普通数据类型。
好的,我创建了一个变量..并将其传递给..同样的错误
if (dbcontroller.DBConnection())
{
Int64 projectCode = 0;
MySqlCommand command = new MySqlCommand("insert_projects", dbcontroller.conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
// Add parameters for the insert_projects STORED PROC
command.Parameters.Add(new MySqlParameter("userName", SessionBag.Current.UserName));
command.Parameters["@userName"].Direction = System.Data.ParameterDirection.Input;
command.Parameters.Add(new MySqlParameter("projectCode", projectCode));
command.Parameters["@projectCode"].Direction = System.Data.ParameterDirection.Output;
它仍然不起作用