Пример #1
0
        public static void CreateDatabaseTest(MainForm frm)
        {
            PFSQLAnywhereUL sqlu             = new PFSQLAnywhereUL();
            string          connectionString = string.Empty;

            try
            {
                _msg.Length = 0;
                _msg.Append("CreateDatabaseTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                if (frm.txtDatabaseFile.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify a database file name for Create Database Test.");
                    throw new DataException(_msg.ToString());
                }

                sqlu.DatabasePath = frm.txtDatabaseFile.Text;
                sqlu.DatabaseName = frm.txtDatabaseName.Text;
                sqlu.Username     = frm.txtUsername.Text;
                sqlu.Password     = frm.txtPassword.Text;

                sqlu.DatabaseKey = frm.txtDatabaseKey.Text;

                connectionString = sqlu.ConnectionString;

                _msg.Length = 0;
                _msg.Append("Connection string is: \r\n");
                _msg.Append(connectionString);
                Program._messageLog.WriteLine(_msg.ToString());


                sqlu.OpenConnection();


                if (File.Exists(@"c:\temp\newSQL.udb"))
                {
                    PFFile.FileDelete(@"c:\temp\newSQL.udb");
                }
                if (File.Exists(@"c:\temp\newSQLenc.udb"))
                {
                    PFFile.FileDelete(@"c:\temp\newSQLenc.udb");
                }

                sqlu.CreateDatabase(@"c:\temp\newSQL.udb", false, string.Empty);
                sqlu.CreateDatabase(@"c:\temp\newSQLenc.udb", true, "testkey");
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                if (sqlu != null)
                {
                    if (sqlu.IsConnected)
                    {
                        sqlu.CloseConnection();
                    }
                }
                sqlu        = null;
                _msg.Length = 0;
                _msg.Append("\r\n... CreateDatabaseTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }