如何解决MySql触发器不会执行整个程序
所以我在 MysqL 中有一个触发器,当它被调用时,用参数执行一个外部 C# 应用程序,它是一个 NamedPipeClient,它应该将这些参数发送到一个已经运行的 PipeServer 应用程序,但它不会正确执行。 显然它不会创建管道客户端实例。 PS:如果手动执行程序可以正常工作,但不会完全从触发器中执行。
触发代码:
installed_rank;version;
description;type;script;checksum;installed_by;installed_on;
execution_time;success
1;1;<< Flyway Baseline >>;BASELINE;<< Flyway Baseline >>;?;null;Apr 28,2021 12:01:32.616 PM;0;1
服务器管道代码:
CREATE DEFINER=`root`@`localhost` TRIGGER `Test_Trigger` BEFORE UPDATE ON `event` FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
DECLARE Arg char(20);
SET ARG = new.DoorNumber;
SET cmd ='cmd /c "cd /d D:\\PipeExSer\\PipeExClient\\bin\\Debug && PipeExClient.exe"';
SET result = sys_exec(cmd);
END
ClientPipe 代码:
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
class PipeServer
{
static void Main()
{
using (NamedPipeServerStream pipeServer =
new NamedPipeServerStream("TP"))
{
Console.WriteLine("NamedPipeSe rverStream object created.");
// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
try
{
// Read user input and send that to the client process.
/* using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
Console.Write("Enter text: ");
sw.WriteLine(Console.ReadLine());
}*/
using (StreamReader sr = new StreamReader(pipeServer))
{
// display the read text to the console
string temp;
while ((temp = sr.ReadLine()) != null)
{
Console.WriteLine("Received from client: {0}",temp);
}
}
}
// Catch the IOException that is raised if the pipe is broken
// or disconnected.
catch (IOException e)
{
Console.WriteLine("ERROR: {0}",e.Message);
}
Console.WriteLine("It reached this");
Console.WriteLine(pipeServer.IsConnected);
Thread.Sleep(5000);
pipeServer.dispose();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。