First I would recommend double-check if you cannot use one of the existing management facilities, like Policy Based Management or Central Management Servers. Specially PBM, it covers many operations that traditionally required something like 'run this script on every database'. There are also many articles describing PBM in action, eg. Policy-based Management and Central Management Servers.
Another thing to consider is to use PowerShell instead of C#/ADO/SMO. PS deliverables are scripts that are easily changed/maintained in production, as opposed to compiled executables. Also the object pipe model of PS makes a lot of tasks easier in PS than in raw C#. PS can use multithreaded execution. See SQL Server PowerShell Overview.
Look into what other projects are out there than handle similar tasks. I myself have a project, dbUtilSqlcmd, that handles executing .SQL files in a ADO.Net environment (handling batch delimiter GO
, handling sqlcmd variables :setvar
and $(variable)
, handling :connect
commands and so on).
Last, if you end up writing code instead of using PBM, your bigger problems are going to be threading and error reporting. Don't start a thread per server/database, 5000 threads are not viable. Use ThreadPool.QueueUserWorkItem
instead. Better still, use the Tasks Parallel Library if possible.