Exemplo n.º 1
0
        //methods

        /// <summary>
        /// Creates SQLCE database file and populates it with required data table.
        /// </summary>
        public void CreateAppLogDatabase()
        {
            string          sqlStmt = string.Empty;
            PFSQLServerCE35 db      = null;

            try
            {
                db = new PFSQLServerCE35();

                db.CreateDatabase(_logConnectionString);

                db.ConnectionString = _logConnectionString;
                db.OpenConnection();

                sqlStmt = _appLogTableCreateSql;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx1;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx2;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx3;
                db.RunNonQuery(sqlStmt);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to create database: ");
                _msg.Append(_logConnectionString);
                if (sqlStmt.Length > 0)
                {
                    _msg.Append(" SQL statement: ");
                    _msg.Append(sqlStmt);
                }
                _msg.Append(" Error message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes all records from Retry Log table.
        /// </summary>
        public void DeleteRetryLogTable()
        {
            string          sqlStmt = string.Empty;
            PFSQLServerCE35 db      = null;

            try
            {
                db = new PFSQLServerCE35(_retryLogConnectionString);

                db.OpenConnection();

                sqlStmt = _retryLogTableDeleteSql;
                db.RunNonQuery(sqlStmt);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to delete table: ");
                _msg.Append(_retryLogConnectionString);
                if (sqlStmt.Length > 0)
                {
                    _msg.Append(" SQL statement: ");
                    _msg.Append(sqlStmt);
                }
                _msg.Append(" Error message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }
        }
Exemplo n.º 3
0
        public static int RunNonQueryTest(MainForm frm, PFSQLServerCE35 db)
        {
            int    numRowsAffected = -1;
            string query           = string.Empty;

            _msg.Length = 0;
            _msg.Append("Running RunNonQueryTest ...");
            Program._messageLog.WriteLine(_msg.ToString());

            try
            {
                query = frm.txtQuery.Text;
                db.OpenConnection();
                numRowsAffected = db.RunNonQuery(query);
                db.CloseConnection();
                _msg.Length = 0;
                _msg.Append("Query: ");
                _msg.Append(frm.txtQuery.Text);
                _msg.Append("\r\n");
                _msg.Append("Num rows affected: ");
                _msg.Append(numRowsAffected.ToString("#,##0"));
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("...RunNonQueryTest Finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }

            return(numRowsAffected);
        }