gpt4 book ai didi

c# - 通过C#将创建过程命令上传到mysql时忽略@symbol

转载 作者:行者123 更新时间:2023-11-29 00:16:23 25 4
gpt4 key购买 nike

我用 C# 创建了一个程序,用于将 MySql 数据库结构和过程复制到新创建的数据库中。然后将新数据上传到它。无法上传其中包含“@”符号的程序的问题,例如:

SET @SEARCH := CONCAT( _SEARCH , '%');

我用来检索程序的代码是:

cmd = new MySqlCommand("SELECT CONCAT( 'CREATE PROCEDURE ', ISR.ROUTINE_NAME, '(', CASE WHEN ISP.PARAMETER_NAME IS NOT NULL THEN GROUP_CONCAT(CONCAT(ISP.PARAMETER_MODE, ' ', ISP.PARAMETER_NAME, ' ', ISP.DTD_IDENTIFIER)) ELSE '' END, ')\n', ISR.ROUTINE_DEFINITION) AS Create_Procedure FROM INFORMATION_SCHEMA.ROUTINES ISR LEFT JOIN INFORMATION_SCHEMA.PARAMETERS ISP ON ISR.ROUTINE_SCHEMA = ISP.SPECIFIC_SCHEMA AND ISR.ROUTINE_NAME = ISP.SPECIFIC_NAME AND ISR.ROUTINE_TYPE = ISP.ROUTINE_TYPE WHERE ROUTINE_SCHEMA = '" + Program.RemoteSource + "' GROUP BY ISR.ROUTINE_NAME;", remote);
using (MySqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
createProcedures.Add(dataReader.GetString(0));
}
};

下面将新的创建过程语句上传到新数据库:

counter = 0;
foreach (string procedure in createProcedures)
{
try
{
cmd = new MySqlCommand(@procedure, remote);
cmd.ExecuteNonQuery();
counter++;
Console.Write("\rProcedures Created: " + counter + " of " + createProcedures.Count);
}
catch (MySqlException ex)
{
Console.WriteLine("Error: {0}", ex.ToString());
}
}

和错误:

Error: MySql.Data.MySqlClient.MySqlException (0x800040005): 
Fatal error encountered during command execution. --->
MySql.Data.MySqlClient.MySqlException (0x800040005):
Parameter '@SEARCH' must be defined.

我该怎么做才能让 MySql.Data 忽略 @ 符号?

最佳答案

我通过在连接字符串中添加 ;Allow User Variables=True 找到了答案。

Is it possible to use a MySql User Defined Variable in a .NET MySqlCommand?

关于c# - 通过C#将创建过程命令上传到mysql时忽略@symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com