Пример #1
0
        private void SqlServerTestConnectionBtn_Click(object sender, RoutedEventArgs e)
        {
            bool windowsAuth = WindowsAuthenticationRadioBtn.IsChecked ?? true;

            SqlConnection connection = DBUtils.CreateSqlServerConnection(
                server: SqlServerHostTextBox.Text,
                username: SqlServerUsernameTextBox.Text,
                password: SqlServerPasswordTextBox.Password,
                useWindowsAuthentication: windowsAuth,
                noDB: true);

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed with error: " + ex.Message);
                return;
            }

            MessageBox.Show("Connection succeeded.");
            connection.Close();
        }