private void btnRefresh_Click(object sender, EventArgs e) { if (ValidateUserInput()) { ConnectionStringProperties objConnectionString = new ConnectionStringProperties(); objConnectionString.DataSource = txtServerName.Text.Trim(); objConnectionString.InitialCatalog = cmbSelectDatabase.SelectedText; objConnectionString.UserId = txtUserName.Text.Trim(); objConnectionString.Password = txtPassword.Text.Trim(); var connectionString = _connectionStringService.BuildConnectionString(objConnectionString, true); if (_dbConnectService.TestConnection(connectionString)) { Global.ConnectionString = connectionString; var lstDatabases = _dbConnectService.GetDatabases().ToList(); if (lstDatabases.Count > 0) { cmbSelectDatabase.DataSource = lstDatabases; cmbSelectDatabase.DisplayMember = "DbName"; cmbSelectDatabase.ValueMember = "DbId"; } } } }
public string BuildConnectionString(ConnectionStringProperties connectionStringProperties, bool blnPartialConnectionString = false) { var settings = ConfigurationManager.ConnectionStrings["sqlConnectionString"]; if (settings != null) { var connectString = settings.ConnectionString; var builder = new SqlConnectionStringBuilder(connectString); builder.DataSource = connectionStringProperties.DataSource; if (blnPartialConnectionString) builder.InitialCatalog = connectionStringProperties.InitialCatalog; if (connectionStringProperties.AuthenticationType == Models.Enums.AuthenticationTypes.SQLServerAuthentication) { builder.UserID = connectionStringProperties.UserId; builder.Password = connectionStringProperties.Password; } else { builder.IntegratedSecurity = true; } builder.MultipleActiveResultSets = true; Global.ConnectionString = builder.ConnectionString; return builder.ConnectionString; } return string.Empty; }
private void btnConnect_Click(object sender, EventArgs e) { if (ValidateUserInput() && ValidateDatabaseSelection()) { ConnectionStringProperties objConnectionString = new ConnectionStringProperties(); objConnectionString.DataSource = txtServerName.Text.Trim(); objConnectionString.InitialCatalog = ((DatabaseName)cmbSelectDatabase.SelectedItem).DbName; objConnectionString.UserId = txtUserName.Text.Trim(); objConnectionString.Password = txtPassword.Text.Trim(); var connectionString = _connectionStringService.BuildConnectionString(objConnectionString, true); if (_dbConnectService.TestConnection(connectionString)) { //Global.ConnectionString = connectionString; LoadDataTypeMappings(); this.Close(); } } }
private void btnTestConnection_Click(object sender, EventArgs e) { if (ValidateUserInput() && ValidateDatabaseSelection()) { ConnectionStringProperties objConnectionString = new ConnectionStringProperties(); objConnectionString.DataSource = txtServerName.Text.Trim(); objConnectionString.InitialCatalog = cmbSelectDatabase.SelectedText; objConnectionString.UserId = txtUserName.Text.Trim(); objConnectionString.Password = txtPassword.Text.Trim(); var connectionString = _connectionStringService.BuildConnectionString(objConnectionString, false); if (_dbConnectService.TestConnection(connectionString)) { Global.ConnectionString = connectionString; MessageBox.Show("Test Connection Succeeded", "Poco Generator", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }