private void btnCreateConnection_Click(object sender, RoutedEventArgs e) { try { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = cmbDataSource.Text; builder.InitialCatalog = txtBD.Text; builder.Encrypt = (bool)chcIncript.IsChecked; builder.ConnectTimeout = int.Parse(cmbTimeWaitCon.Text); builder.LoadBalanceTimeout = int.Parse(cmbTimeWaitExecute.Text); builder.IntegratedSecurity = !(bool)chcIntegratedSecurity.IsChecked; if (chcIntegratedSecurity.IsChecked == true) { builder.Password = password.Password; builder.UserID = txtuser.Text; } builder.Pooling = false; SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM " + TableName.Text, builder.ConnectionString); adapter.Fill(table); MainWindow.TableName = TableName.Text; MainWindow.BDName = txtBD.Text; this.Close(); } catch (Exception ex) { Attention attention = new Attention("Ошибка подключения " + ex.Message); attention.ShowDialog(); } }
private void Test_Click(object sender, RoutedEventArgs e) { try { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = cmbDataSource.Text; builder.InitialCatalog = txtBD.Text; builder.Encrypt = (bool)chcIncript.IsChecked; builder.ConnectTimeout = int.Parse(cmbTimeWaitCon.Text); builder.LoadBalanceTimeout = int.Parse(cmbTimeWaitExecute.Text); builder.IntegratedSecurity = !(bool)chcIntegratedSecurity.IsChecked; if (chcIntegratedSecurity.IsChecked == true) { builder.Password = password.Password; builder.UserID = txtuser.Text; } builder.Pooling = false; SqlConnection connection = new SqlConnection(builder.ConnectionString); connection.Open(); Attention attention = new Attention("Подключение успешно"); attention.ShowDialog(); connection.Close(); } catch (Exception ex) { Attention attention = new Attention("Ошибка подключения " + ex.Message); attention.ShowDialog(); } }