private void CreateSQLDatabase() { //FileInfo file = null; DbCommand command = null; int ProcessedFileCount = 0; try { #region ConnectToDatabase string connectionString = string.Empty; if (UserName != string.Empty && PassWord != string.Empty) { connectionString = string.Format("Data Source={0};User ID={1};Password={2};Initial Catalog ={3}", ServerName, UserName, PassWord, DataBase); } else { connectionString = string.Format("Data Source={0};Integrated Security=True;Initial Catalog={1};", ServerName, DataBase); } SqlCommand EMSDb = new SqlCommand(); SqlConnection conn = new SqlConnection(connectionString); // WriteLog(string.Format("Regression Test ran on {0} using user \"{1}\"", DataBase, UserName), TraceEventType.Information); #endregion // Set the total number of avaliable files _progressEventArgs.FileCount = _fileNameList.Count; for (int count = 0; count < _fileNameList.Count; count++) { if (_fileNameList[count] != null) { if (!_backProcess.CancellationPending) { string fileName = _fileNameList[count].Substring(_fileNameList[count].LastIndexOf("\\") + 1, _fileNameList[count].Length - _fileNameList[count].LastIndexOf("\\") - 1); WriteLog(string.Format("Processing file: {0}", fileName), TraceEventType.Information); string dbQuery; using (var reader = new StreamReader(_fileNameList[count], Encoding.Default)) { dbQuery = reader.ReadToEnd(); } _progressEventArgs.HasError = false; try { _progressEventArgs.ProcessedFileCount = ++ProcessedFileCount; _progressEventArgs.ProcessingFileName = fileName; NotifyProgress(this, _progressEventArgs); SqlConnection sqlConnection = new SqlConnection(connectionString); ServerConnection svrConnection = new ServerConnection(sqlConnection); Server server = new Server(svrConnection); server.ConnectionContext.ExecuteNonQuery(dbQuery); } catch (Exception exp) { conn.Close(); _progressEventArgs.ProcessingFileName = fileName; _progressEventArgs.HasError = true; NotifyProgress(this, _progressEventArgs); if (!_hasErrors && _progressEventArgs.HasError) _hasErrors = true; WriteLog(string.Format("Error while executing {0}: {1}", fileName, exp.InnerException.Message), TraceEventType.Error); if (NotifyProcessError != null) { DialogResult dlgResults = NotifyProcessError(this, new ProcessErrorEventArgs(fileName, ProcessedFileCount, _fileNameList.Count)); if (dlgResults == DialogResult.Abort) _backProcess.CancelAsync(); else if (dlgResults == DialogResult.Retry) count--; } } } else _isSuccessful = false; } } _isSuccessful = true; } catch (Exception exp) { WriteLog(string.Format("Error: {0}", exp.Message), TraceEventType.Error); _isSuccessful = false; } finally { //file = null; if (command != null) { command.Dispose(); command = null; } } if (NotifyProcessComplete != null) NotifyProcessComplete(this, new EventArgs()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)