/// <summary>
        /// Build the connection string
        /// </summary>
        /// <param name="SmiConnectionString">Connection string info</param>
        /// <returns>Connection string</returns>
        public virtual string BuildConnectionString(ISmiConnectionStringInfo SmiConnectionString)
        {
            if (SmiConnectionString is null)
            {
                throw new ArgumentNullException(nameof(SmiConnectionString));
            }

            var builder = new SqlConnectionStringBuilder
            {
                DataSource          = SmiConnectionString.ServerName,
                InitialCatalog      = SmiConnectionString.DatabaseName,
                PersistSecurityInfo = false,
                IntegratedSecurity  = SmiConnectionString.IntegratedSecurity
            };

            if (!SmiConnectionString.IntegratedSecurity)
            {
                builder.UserID   = SmiConnectionString.Username;
                builder.Password = SmiConnectionString.Password;
            }

            return(builder.ConnectionString);
        }
Example #2
0
        /// <summary>
        /// Build the connection string
        /// </summary>
        /// <param name="SmiConnectionString">Connection string info</param>
        /// <returns>Connection string</returns>
        public virtual string BuildConnectionString(ISmiConnectionStringInfo SmiConnectionString)
        {
            if (SmiConnectionString is null)
            {
                throw new ArgumentNullException(nameof(SmiConnectionString));
            }

            if (SmiConnectionString.IntegratedSecurity)
            {
                throw new SmiException("Data provider supports connection only with login and password");
            }

            var builder = new MySqlConnectionStringBuilder
            {
                Server = SmiConnectionString.ServerName,
                //Cast DatabaseName to lowercase to avoid case-sensitivity problems
                Database           = SmiConnectionString.DatabaseName.ToLower(),
                AllowUserVariables = true,
                UserID             = SmiConnectionString.Username,
                Password           = SmiConnectionString.Password,
            };

            return(builder.ConnectionString);
        }