Example #1
0
        private void btn_enter_Click(object sender, EventArgs e)
        {
            /// Set up the client computer connection to the server

            if (txt_DBName.Text == "" || txt_DBPassword.Text == "" || txt_serverIP.Text == "")
            {
                MessageBox.Show("Please enter all requests.");
                return;
            }

            var EntityConnectionString = BuildEntityConnection("Data Source=" + txt_serverIP.Text.Trim() + ";Initial Catalog=" + txt_DBName.Text.Trim()
                                                               + ";user Id=sa;Password="******";Integrated Security=false"); /// The last phrase means do not enter without a password, be sure to get a password.

            try
            {
                RegistryKey connctionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\AutomationConnection");
                try
                {
                    connctionKey.SetValue("ConnectionForAutomation", CryptionAlgorithm.EncryptTextUsingUTF8(EntityConnectionString));
                }
                catch
                {
                    MessageBox.Show("There is a problem with the server.");
                }
                finally
                {
                    connctionKey.Close();
                }

                MessageBox.Show("The connection to the server was established successfully. Please log out and log back in.");
                this.Close();
            }
            catch
            {
                MessageBox.Show("There is a problem with the server.");
            }
        }