private string InitializeConnection(DatabaseConnectionInfo connectionInfo)
        {
            string result = null;

            try
            {
                SqlConnection connection = new SqlConnection(connectionInfo.ConnectionString);
                connection.Open();
                this.sqlConnection = connection;
                this.UserId = GetUserId();
            }
            catch (Exception ex)
            {
                if (ex is InvalidOperationException || ex is SqlException)
                {
                    result = "There was an error connecting to the database. " + ex.Message;
                }
                else
                {
                    throw;
                }
            }

            return result;
        }
        private DatabaseConnectionInfo SettingsToConnectionInfo(Properties.Settings settings)
        {
            var connectionInfo = new DatabaseConnectionInfo
            {
                ServerName = settings.ServerName,
                UseWindowsAuthentication = settings.UseWindowsAuthentication,
                DatabaseName = settings.DatabaseName
            };

            if (!settings.UseWindowsAuthentication)
            {
                connectionInfo.UserName = settings.UserName;
                connectionInfo.EncryptedPassword = settings.Password;
            }

            return connectionInfo;
        }
 private static void SettingsFromConnectionInfo(DatabaseConnectionInfo connectionInfo, Properties.Settings settings)
 {
     settings.ServerName = connectionInfo.ServerName;
     settings.UseWindowsAuthentication = connectionInfo.UseWindowsAuthentication;
     settings.DatabaseName = connectionInfo.DatabaseName;
     if (!connectionInfo.UseWindowsAuthentication)
     {
         settings.UserName = connectionInfo.UserName;
         if (connectionInfo.RememberPassword)
         {
             settings.Password = connectionInfo.EncryptedPassword;
         }
     }
     else
     {
         settings.UserName = string.Empty;
         settings.Password = string.Empty;
     }
 }