Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnSaveConnection_Click(object sender, EventArgs e)
- {
- string warnEmptyField = "Spceifier un Id Utilisateur et un mot de pass";
- string serverName = string.Empty;
- string db_name = string.Empty;
- if (txtServerName.Text.Trim() != string.Empty)
- {
- if (cbConnectionType.SelectedIndex == 0)
- {
- serverName = @".\";
- serverName += txtServerName.Text.Trim();
- }
- else
- {
- serverName = txtServerName.Text.Trim();
- }
- connectionStringBuilder.DataSource = serverName;
- }
- else
- {
- warnEmptyField = "Spceifier le nom du serveur";
- MessageBox.Show(warnEmptyField, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (String.IsNullOrEmpty(txtBDName.Text) == false)
- {
- db_name = txtBDName.Text.Trim();
- connectionStringBuilder.InitialCatalog = db_name;
- }
- else
- {
- warnEmptyField = "Spceifier votre Base de donnée";
- MessageBox.Show(warnEmptyField, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (cbIntegratedSecurity.Checked)
- {
- connectionStringBuilder.IntegratedSecurity = true;
- }
- else
- {
- if (String.IsNullOrEmpty(txtUserName.Text) == false &&
- String.IsNullOrEmpty(txtUserName.Text))
- {
- connectionStringBuilder.UserID = txtUserName.Text;
- connectionStringBuilder.Password = txtPassword.Text;
- }
- else
- {
- warnEmptyField = "Spceifier un ID Utilisateur et un mot de pass";
- MessageBox.Show(warnEmptyField, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- try
- {
- try
- {
- bool connected = TestConnectionString(connectionStringBuilder.ToString());
- if (connected)
- {
- MessageBox.Show("Connection Etablie", "Success",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- connectionSet = true;
- tab_BasicInfos.PageVisible = true;
- tabs.SelectedTabPage = tab_BasicInfos;
- tabConnectionConfig.PageVisible = false;
- currentConfig.ConnectionString = connectionStringBuilder.ToString();
- DataSource.InitConnection(connectionStringBuilder.ToString());
- }
- else
- {
- MessageBox.Show("Connection Non Etablie", "Erreur",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("Connection Non Etablie", "Erreur",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- DataSource.DisposeConnection();
- }
- }
- catch (Exception)
- {
- MessageBox.Show("Erreur de connection...\nImpossible d'atteindre le serveur fournis" +
- "Veullez verfier vos parametres de connection et ressayer", "Erreur",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- DataSource.DisposeConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement