Пример #1
0
 public static void RunScript(string scriptPath)
 {
     using (DatabaseContext _DatabaseContext = new DatabaseContext())
     {
         _DatabaseContext.ExecuteStoreCommand(Filer.ReadFromFile(scriptPath));
     }
 }
Пример #2
0
 public static void DeleteDatabaseIfExists()
 {
     using (DatabaseContext _DatabaseContext = new DatabaseContext())
     {
         if (_DatabaseContext.DatabaseExists())
             _DatabaseContext.DeleteDatabase();
     }
 }
Пример #3
0
 public static void CreateDatabaseIfDoesNotExist()
 {
     using (DatabaseContext _DatabaseContext = new DatabaseContext())
     {
         if (!_DatabaseContext.DatabaseExists())
             _DatabaseContext.CreateDatabase();
     }
 }
Пример #4
0
        public static string TestSqlClientConnectionString()
        {
            string connStr = string.Empty;

            using (DatabaseContext _db = new DatabaseContext())
            {
                connStr = (_db.Connection as System.Data.EntityClient.EntityConnection).StoreConnection.ConnectionString;
            }

            return TestSqlClientConnectionString(connStr);
        }
Пример #5
0
 public void ConnectionTest_OpensAConnection_ShouldPassIfSuccessful()
 {
     try
     {
         using (DatabaseContext db = new DatabaseContext())
         {
             db.Connection.Open();
             db.Connection.Close();
         }
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
Пример #6
0
        protected void buttonCreateDatabase_Click(object sender, EventArgs e)
        {
            try
            {
                string newConnectionString = BuildEntityFrameworkConnectionStringForSqlClient
                    (
                        txtServerAddress.Text,
                        txtDbName.Text,
                        chkUseIntegratedSecurity.Checked,
                        txtUsername.Text,
                        txtPassword.Text

                    );

                //create database
                using (DatabaseContext _DatabaseContext = new DatabaseContext())
                {
                    ((EntityConnection)_DatabaseContext.Connection).StoreConnection.ConnectionString = BuildSqlClientConnectionString
                        (
                        txtServerAddress.Text,
                        txtDbName.Text,
                        chkUseIntegratedSecurity.Checked,
                        txtUsername.Text,
                        txtPassword.Text

                    );

                    if (!_DatabaseContext.DatabaseExists())
                    {
                        _DatabaseContext.CreateDatabase();
                    }
                }

                //save the new db connectionstring to config files

                SaveConnectionStringKey(Server.MapPath("~/web.config"), "DatabaseContext", newConnectionString);

                //show the proper message
                labelMessage.Text = MessageFormatter.GetFormattedNoticeMessage("Database created successfully. Click the Create 'Install Schema and Data' button to install database.");
                buttonInstall.Visible = true;
                txtDbName.ReadOnly = true;
            }
            catch (Exception ex)
            {
                labelMessage.Text = MessageFormatter.GetFormattedErrorMessage("Database creation failed: " + ex.Message);
                buttonInstall.Visible = false;
            }
        }