public string BuildConnectionString(INopConnectionStringInfo nopConnectionString)
        {
            if (nopConnectionString is null)
            {
                throw new ArgumentNullException(nameof(nopConnectionString));
            }

            if (nopConnectionString.IntegratedSecurity)
            {
                throw new NopException("Data provider supports connection only with password");
            }

            var builder = new SqliteConnectionStringBuilder
            {
                DataSource = CommonHelper.DefaultFileProvider.MapPath($"~/App_Data/{nopConnectionString.DatabaseName}.sqlite"),
                Password   = nopConnectionString.Password,
                Mode       = SqliteOpenMode.ReadWrite,
                Cache      = SqliteCacheMode.Shared
            };

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

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

            var builder = new NpgsqlConnectionStringBuilder
            {
                Host = nopConnectionString.ServerName,
                //Cast DatabaseName to lowercase to avoid case-sensitivity problems
                Database = nopConnectionString.DatabaseName.ToLower(),
                Username = nopConnectionString.Username,
                Password = nopConnectionString.Password,
            };

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

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

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

            return(builder.ConnectionString);
        }