Esempio n. 1
0
        private void Form_Login_Load(object sender, EventArgs e)
        {
            //Checks if connection to the DB is possible
            IDbConnection con = new LogamoastaEntities().Database.Connection;

            try
            {
                con.Open();
                //Split the connectionstring, so only the web location of the db will be shown "Verbunden zu eduweb.kb.local" for example
                string[] connectionsite = con.ConnectionString.Split('=', ';');
                lbl_connection.Text = "Verbunden zu '" + connectionsite[1] + "'.";
            }
            catch
            {
                lbl_connection.Text  = "Verbindung zur Datenbank nicht möglich!";
                btn_anmelden.Enabled = false;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }

            if (lbl_connection.Text == "Verbindung zur Datenbank nicht möglich!")
            {
                LogamoastaEntities hakkitzcon = new LogamoastaEntities();
                //replace the connection with web.hak-kitz.at
                hakkitzcon.Database.Connection.ConnectionString = hakkitzcon.Database.Connection.ConnectionString.Replace("eduweb.kb.local", "web.hak-kitz.at");

                IDbConnection con2 = hakkitzcon.Database.Connection;
                try
                {
                    con2.Open();
                    //Split the connectionstring, so only the web location of the db will be shown "Verbunden zu eduweb.kb.local" for example
                    string[] connectionsite = con2.ConnectionString.Split('=', ';');
                    lbl_connection.Text = "Verbunden zu '" + connectionsite[1] + "'.";
                    entity.Database.Connection.ConnectionString = hakkitzcon.Database.Connection.ConnectionString;
                    btn_anmelden.Enabled = true;
                }
                catch
                {
                    lbl_connection.Text  = "Verbindung zur Datenbank nicht möglich!";
                    btn_anmelden.Enabled = false;
                }
                finally
                {
                    if (con2.State == ConnectionState.Open)
                    {
                        con2.Close();
                    }
                }
            }
        }