简体   繁体   English

从客户端C#在远程服务器上执行长脚本的最佳方法

[英]Best approach to execute long scripts on remote server from client c#

I have a number of script files to be executed on remote sql server databases from client c# code. 我有许多脚本文件要从客户端c#代码在远程sql服务器数据库上执行。 The same script files need to be executed on various servers in same sequence. 相同的脚本文件需要在不同的服务器上以相同的顺序执行。 eg there are following: 例如:
Files -- "file1.sql", "file2.sql", "file3.sql" & Database Servers -- "server1", "server2", "server3" (this will be around 100) with Database -- "testdb" present on each database server, then I need to execute file1.sql then file2.sql and then file3.sql on testdb database on each of server1, server2 and server3 parallely. 文件-“ file1.sql”,“ file2.sql”,“ file3.sql”和数据库服务器-“ server1”,“ server2”,“ server3”(大约为100),数据库-“ testdb”存在于每个数据库服务器上,那么我需要并行执行server1,server2和server3上的testdb数据库上的file1.sql,然后执行file2.sql,然后执行file3.sql。

Since I want to execute the scripts parallely on all servers, so I am planning to use Task Parallel Library's Parallel.for loop to create threads and execute parallely on database servers through c# code. 由于我想在所有服务器上并行执行脚本,因此我打算使用任务并行库的Parallel.for循环创建线程并通过c#代码在数据库服务器上并行执行。 I am planning to use smo objects to execute sql server scripts from c# code. 我打算使用smo对象从c#代码执行sql服务器脚本。

Please advise if what i am thinking makes sense to use tpl library to execute scripts on sql server from c# code or is there some other better approach that i can follow. 请告知我使用tpl库从c#代码在sql服务器上执行脚本是否有意义,或者我可以遵循其他更好的方法。

One important fact that will be there in production is that there will be around 100 databases(database servers). 生产中将要存在的一个重要事实是,将有大约100个数据库(数据库服务器)。

All responses and advises are appreciated. 感谢您的所有回应和建议。

Thanks. 谢谢。

Some More Information Added: I think tpl's Task class uses thread pool thread, so if there are 100 threads to be created for execution on 100 databases, then it may be a problem as it may use all the thread pool threads(thread pool normally has 25 threads) and the server may get choked. 添加了一些更多信息:我认为tpl的Task类使用线程池线程,因此,如果要创建100个线程以在100个数据库上执行,则可能会出现问题,因为它可能会使用所有线程池线程(线程池通常具有25个线程),服务器可能会阻塞。 Also as there are a limited number of thread pool threads and it is not a good choice to use threadpool threads for long running tasks, so would we need to implement our own implementation to manage the threads? 另外,由于线程池线程数有限,并且对于长时间运行的任务而言,使用线程池线程不是一个好选择,那么我们是否需要实现自己的实现来管理线程?

Tpl is a fine way to approach this. Tpl是解决此问题的好方法。 Another possible way is powershell with jobs. 另一种可能的方法是使用作业进行Powershell。 Only reason I bring up powershell is that powershell script may be more flexible to maintain and execute for this type of thing. 我提到powershell的唯一原因是,对于此类事情,powershell脚本可能更灵活地维护和执行。 Take a look at this discussion . 一下这个讨论 But nothing wrong doing it in C# with TPL, either. 但是使用TPL在C#中执行此操作也没错。

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

相关问题 C#中服务器/客户端通信的最佳冗余方法 - Best redundant approach for server / client communications in C# C#从远程客户端上的远程服务器运行可执行文件 - C# run executable from remote server on remote client 从C#执行包含远程服务器上的Sharepoint命令的Powershell - Execute Powershell containing Sharepoint commands on remote server, from C# 远程访问C#应用程序(Win)的最佳方法? - Remote access to C# Application (Win) best approach? 从服务器到客户端计算机C#执行远程应用程序 - Executing a remote application from server to client machine C# 比较来自客户端浏览器和远程服务器的DateTime,C# - Compare DateTime from client browser and remote server, C# Java Web服务将数据发送到C#客户端的最佳方法 - Best approach for Java web service sending data to C# client 从C ++服务器到C#客户端流很长的流无符号 - Stream unsigned long long from C++ server to C# client C# TcpClient - 客户端确定远程服务器是否正常关闭连接的最佳方法是什么? - C# TcpClient - What's the best way for a client to determine if remote server has gracefully shutdown connection? 使用C#无法在Sql Server 2017中执行Sql脚本 - Unable to execute Sql scripts in Sql Server 2017 by using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM