В Program.cs у меня есть метод ниже, который проверяет и синхронизирует 5 БД SQL с центральным сервером. Каждый из них отделен от другого, поэтому я решил ускорить загрузку моей программы, запустив их все одновременно.
К сожалению, работать один раз очень плохо, а потом - нет. Локальная БД - SQLExpress 2005, а центральная БД - SQL Server Standard 2005.
Существует ли ограничение на количество соединений, которое может иметь одно из них? Как насчет Фоновых Рабочих, я могу только так много бегать одновременно? Я уверен, что есть гораздо более красноречивый способ сделать это, я хотел бы услышать (увидеть) их.
Так я называю это в Main () в Program.cs ->
if(IsSqlAvailable())
SyncNow();
internal static void SyncNow()
{
#region ConnectDB Merge Sync Background Thread
BackgroundWorker connectBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
connectBW.DoWork += new DoWorkEventHandler(connectBW_DoWork);
if (connectBW.IsBusy != true)
connectBW.RunWorkerAsync();
#endregion
#region aspnetDB Merge Sync Background Thread
BackgroundWorker aspBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
aspBW.DoWork += new DoWorkEventHandler(aspBW_DoWork);
if (aspBW.IsBusy != true)
aspBW.RunWorkerAsync();
#endregion
#region MatrixDB Merge Sync Background Thread
BackgroundWorker matrixBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
matrixBW.DoWork += new DoWorkEventHandler(matrixBW_DoWork);
if (matrixBW.IsBusy != true)
matrixBW.RunWorkerAsync();
#endregion
#region CMODB Merge Sync Background Thread
BackgroundWorker cmoBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
cmoBW.DoWork += new DoWorkEventHandler(cmoBW_DoWork);
if (cmoBW.IsBusy != true)
cmoBW.RunWorkerAsync();
#endregion
#region MemberCenteredPlanDB Merge Sync Background Thread
BackgroundWorker mcpBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
mcpBW.DoWork += new DoWorkEventHandler(mcpBW_DoWork);
if (mcpBW.IsBusy != true)
mcpBW.RunWorkerAsync();
#endregion
}
static void mcpBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl mcpMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MemberCenteredPlan", "MemberCenteredPlan", "MemberCenteredPlan");
mcpMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void cmoBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl cmoMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CMO", "CMO", "CMO");
cmoMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void connectBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl connectMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CONNECT", "Connect", "Connect");
connectMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void matrixBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl matrixMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MATRIX", "MATRIX", "MATRIX");
matrixMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void aspBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl aspnetdbMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "aspnetdb", "aspnetdb", "aspnetdb");
aspnetdbMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}