Пример #1
0
        void s_InfoMessage(object sender, SqlInfoMessageEventArgs e)
        {
            string info = string.Format(SQLSchemaTool.ERRORFORMAT, e.Message, e.Source, string.Empty);

            logger.Info(SQLSchemaTool.ERRORFORMAT, e.Message, e.Source, string.Empty);
            HTMLDoc hDoc = new HTMLDoc("SQL Query Execution Info Report");

            hDoc.HTMLText = info;
            hDoc.Show(this.DockPanel);
        }
Пример #2
0
 public void RunSQLScript()
 {
     if (m_serverExplorer != null)
     {
         SQLSecuritySettings sss = new SQLSecuritySettings(m_serverExplorer);
         DialogResult        dr  = sss.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             string connectionstr = string.Format(SQLConnections._secureConnect, sss.SelectedDBName, sss.SelectedSQLServer);
             if (sss.SecurityMode() == SecurityType.Mixed)
             {
                 connectionstr = string.Format(SQLConnections._secureConnect, sss.SelectedDBName, sss.SelectedSQLServer, sss.User, sss.PWD);
             }
             using (SqlConnection s = new SqlConnection(connectionstr))
             {
                 int rows = 0;
                 try
                 {
                     s.InfoMessage += new SqlInfoMessageEventHandler(s_InfoMessage);
                     s.Open();
                     using (SqlCommand sc = s.CreateCommand())
                     {
                         // C01: LLEWIS: add test for GO statements to break up executequery statements
                         string[] statements = GetText().ToLower().Split(new string[] { "go" }, StringSplitOptions.RemoveEmptyEntries);
                         foreach (string statement in statements)
                         {
                             sc.CommandText = statement;
                             try { sc.Prepare(); }
                             catch { } // NOP, don't care about errors from this
                             rows = sc.ExecuteNonQuery();
                         }
                     } // dispose of SqlCommand: sc
                     s.Close();
                     s.InfoMessage -= new SqlInfoMessageEventHandler(s_InfoMessage);
                     MessageBox.Show("The SQL command was successful.", "SQL Info!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 catch (SqlException sqe)
                 {
                     s.Close();
                     string error = string.Format(SQLSchemaTool.ERRORFORMAT, sqe.Message, sqe.Source, sqe.StackTrace);
                     logger.Warn(SQLSchemaTool.ERRORFORMAT, sqe.Message, sqe.Source, sqe.StackTrace);
                     HTMLDoc hDoc = new HTMLDoc("SQL Error Report");
                     hDoc.HTMLText = error;
                     hDoc.Show(this.DockPanel);
                     MessageBox.Show("There was an error executing the SQL command:\n" + error, "SQL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
         else if (dr == DialogResult.Abort)
         {
             logger.Warn("You must set the server security first!");
             MessageBox.Show("You must set the server security first!\nUse the SQL Server Explorer.", "SQL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Пример #3
0
 private void CompareData()
 {
     if (selectedTables[0] != null && selectedTables[1] != null)
     {
         if (m_serverExplorer.SelectedTablesCount > 2)
         {
             MessageBox.Show("Only first two Tables are used for compare!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         string sourceQuery = "select * from " + selectedTables[0].FullTablePath;
         SqlConnection source = ((ServerTreeNode)selectedTables[0].Parent.Parent).SQLServerConnection;
         string targetQuery = "select * from " + selectedTables[1].FullTablePath;
         SqlConnection target = ((ServerTreeNode)selectedTables[1].Parent.Parent).SQLServerConnection;
         string htmlReportName = "TableDiffReport.html";
         HTMLDoc hDoc = new HTMLDoc(htmlReportName);
         hDoc.InitialDirectory = LastDirectory;
         string m_DialogTitle = "Save HTML File As...";
         string m_DialogTypeFilter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
         string m_fileName = htmlReportName;
         ArrayList arl = hDoc.ShowSaveFileDialog(m_fileName, m_DialogTitle, m_DialogTypeFilter);
         DialogResult dr = (DialogResult)arl[0];
         if (htmlReportName != null && htmlReportName != string.Empty)
         {
             if (dr == DialogResult.OK)
             {
                 htmlReportName = SQLData.CompareData(sourceQuery, targetQuery, source, target, false);
                 if (htmlReportName != null && htmlReportName != string.Empty)
                 {
                     m_fileName = (string)arl[1];
                     File.WriteAllText(m_fileName, File.ReadAllText(htmlReportName));
                     hDoc.DefaultView = true;
                     //hDoc.HTMLText = File.ReadAllText(htmlReportName);
                     hDoc.FileName = m_fileName;
                     hDoc.Show(dockPanel);
                     LastDirectory = hDoc.InitialDirectory;
                 }
             }
         }
         else
         {
             hDoc.Close();
             hDoc.Dispose();
         }
     }
     m_serverExplorer.deselectDBTables();
 }
Пример #4
0
 private void openHTML(bool defaultView)
 {
     // load html report
     String fileName = null;
     HTMLDoc hDoc = new HTMLDoc("Report");
     hDoc.InitialDirectory = LastDirectory;
     hDoc.DefaultView = defaultView;
     hDoc.DocumentLoaded += new EventHandler<WebBrowserDocumentCompletedEventArgs>(hDoc_DocumentLoaded);
     
     if (dockPanel.ActiveDocument != null && typeof(XMLDoc).IsInstanceOfType(dockPanel.ActiveDocument.DockHandler.Form))
     {
         XMLDoc doc = (XMLDoc)dockPanel.ActiveDocument.DockHandler.Form;
         if (doc.IsDatabaseDiff || doc.IsDatabaseSchema)
         {
             hDoc.DefaultView = false;
         }
         else
         {
             hDoc.DefaultView = true;
         }
         fileName = doc.FileName;
     }
     disableProgressIndicator();
     if (fileName != null)
     {
         hDoc.FileName = fileName;
         hDoc.Show(dockPanel);
         LastDirectory = hDoc.InitialDirectory;
     }
     else
     {
         // BUG FIX 08-02-2007 reported: awittig
         if (!hDoc.Open(dockPanel))
         {
             return;
         }
         else
         {
             LastDirectory = hDoc.InitialDirectory;
         }
     }
     this.toolStripStatusLabel1.Text = string.Format("Loading Report: {0}", fileName);
     this.timer1.Enabled = true;
     this.progressIndicator.Visible = true;
     this.progressIndicator.Value = 0;
 }
Пример #5
0
 void s_InfoMessage(object sender, SqlInfoMessageEventArgs e)
 {
     string info = string.Format(SQLSchemaTool.ERRORFORMAT, e.Message, e.Source, string.Empty);
     logger.Info(SQLSchemaTool.ERRORFORMAT, e.Message, e.Source, string.Empty);
     HTMLDoc hDoc = new HTMLDoc("SQL Query Execution Info Report");
     hDoc.HTMLText = info;
     hDoc.Show(this.DockPanel);
 }
Пример #6
0
 public void RunSQLScript()
 {
     if (m_serverExplorer != null)
     {
         SQLSecuritySettings sss = new SQLSecuritySettings(m_serverExplorer);
         DialogResult dr = sss.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             string connectionstr = string.Format(SQLConnections._secureConnect, sss.SelectedDBName, sss.SelectedSQLServer);
             if (sss.SecurityMode() == SecurityType.Mixed)
             {
                 connectionstr = string.Format(SQLConnections._secureConnect, sss.SelectedDBName, sss.SelectedSQLServer, sss.User, sss.PWD);
             }
             using (SqlConnection s = new SqlConnection(connectionstr))
             {
                 int rows = 0;
                 try
                 {
                     s.InfoMessage += new SqlInfoMessageEventHandler(s_InfoMessage);
                     s.Open();
                     using (SqlCommand sc = s.CreateCommand())
                     {
                         // C01: LLEWIS: add test for GO statements to break up executequery statements
                         string[] statements = GetText().ToLower().Split(new string[]{"go"}, StringSplitOptions.RemoveEmptyEntries);
                         foreach (string statement in statements)
                         {
                             sc.CommandText = statement;
                             try { sc.Prepare(); }
                             catch { } // NOP, don't care about errors from this
                             rows = sc.ExecuteNonQuery();                                    
                         }
                     } // dispose of SqlCommand: sc
                     s.Close();
                     s.InfoMessage -= new SqlInfoMessageEventHandler(s_InfoMessage);
                     MessageBox.Show("The SQL command was successful.", "SQL Info!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 catch (SqlException sqe)
                 {
                     s.Close();
                     string error = string.Format(SQLSchemaTool.ERRORFORMAT, sqe.Message, sqe.Source, sqe.StackTrace);
                     logger.Warn(SQLSchemaTool.ERRORFORMAT, sqe.Message, sqe.Source, sqe.StackTrace);
                     HTMLDoc hDoc = new HTMLDoc("SQL Error Report");
                     hDoc.HTMLText = error;
                     hDoc.Show(this.DockPanel);
                     MessageBox.Show("There was an error executing the SQL command:\n" + error, "SQL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
         else if (dr == DialogResult.Abort)
         {
             logger.Warn("You must set the server security first!");
             MessageBox.Show("You must set the server security first!\nUse the SQL Server Explorer.", "SQL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }