简体   繁体   English

将SQL传输到MySQL C#监视程序

[英]Transfer SQL to MySQL C# Monitoring Program

I currently have a working program that is monitoring a few SQL tables and transferring data to MySQL tables. 我目前有一个正在运行的程序,该程序正在监视一些SQL表并将数据传输到MySQL表。 Essentially, I have a loop that checks every 30 seconds. 本质上,我有一个循环,每30秒检查一次。 My main concern is that I currently need to close and open the connection every time I loop. 我主要担心的是,我每次循环时都需要关闭和打开连接。 The reason for this is because I was getting errors about multiple transactions. 这样做的原因是因为我收到有关多个事务的错误。 When I close my connections, I also need to dispose the connection. 当我关闭连接时,我还需要释放连接。 I thought that disposing the transactions would have solved this problem, but I was still getting errors about multiple transactions. 我以为处置这些事务可以解决此问题,但是我仍然遇到有关多个事务的错误。

This all seems to be working fine but I was wondering if there was a better way to do this without closing the connection. 这一切似乎都工作正常,但我想知道是否有更好的方法可以在不关闭连接的情况下执行此操作。

I am not sure about your errors but it seems that you have to increase the number of connections to the remote computer. 我不确定您的错误,但似乎您必须增加与远程计算机的连接数。 Have a look here http://msdn.microsoft.com/en-us/library/system.net.configuration.connectionmanagementelement.maxconnection.aspx 在这里看看http://msdn.microsoft.com/en-us/library/system.net.configuration.connectionmanagementelement.maxconnection.aspx

Also you can try to do is use only one connection to realize multiple SQLs. 您也可以尝试仅使用一个连接来实现多个SQL。

If it is doesn't help then please provide your code to check it... 如果没有帮助,请提供您的代码进行检查...

Were you committing your transactions in your loop? 您是否在循环中提交交易? transaction.Commit() ... that could have been the issue... Hard to say with no code. transaction.Commit() ...可能是问题所在...没有代码很难说。 No need to worry about opening and closing connections anyways since ADO.NET uses connection pooling behind the scenes. 无论如何,无需担心打开和关闭连接的麻烦,因为ADO.NET在后台使用了连接池。 You only actually 'open' a connection the first time, after that is kept open in the pool to be used again. 您实际上只是第一次“打开”连接,然后在池中保持打开状态以再次使用。 As others have said though, Post some code! 正如其他人所说,发布一些代码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM