nopSolutions/nopCommerce · error · NopException

Data provider supports connection only with login and passwo

Error message

Data provider supports connection only with login and password

What it means

MySqlDataProvider.BuildConnectionString rejects INopConnectionStringInfo with IntegratedSecurity=true. MySQL has no equivalent of SQL Server Windows Authentication in this provider, so the builder requires an explicit UserID/Password. It throws NopException before constructing the MySqlConnectionStringBuilder.

Source

Thrown at src/Libraries/Nop.Data/DataProviders/MySqlDataProvider.cs:292

    public virtual async Task<long> GetDatabaseSizeAsync()
    {
        using var currentConnection = CreateDataConnection();
        var result = await currentConnection.QueryToListAsync<long>($"SELECT ROUND(SUM(data_length + index_length) / 1024, 1) FROM information_schema.tables where table_schema='{GetConnectionStringBuilder().Database}' GROUP BY table_schema");

        return result.FirstOrDefault();
    }

    /// <summary>
    /// Build the connection string
    /// </summary>
    /// <param name="nopConnectionString">Connection string info</param>
    /// <returns>Connection string</returns>
    public virtual string BuildConnectionString(INopConnectionStringInfo nopConnectionString)
    {
        ArgumentNullException.ThrowIfNull(nopConnectionString);

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

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

        return builder.ConnectionString;
    }

    /// <summary>
    /// Gets the name of a foreign key
    /// </summary>

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Set IntegratedSecurity=false and supply Username and Password for the MySQL connection.
  2. If migrating from SQL Server, regenerate the connection configuration for MySQL rather than reusing it.
  3. Validate the IntegratedSecurity flag against the chosen provider in install configuration validation.

Example fix

// before
info.IntegratedSecurity = true; // copied from SQL Server config
var cs = dataProvider.BuildConnectionString(info);

// after
info.IntegratedSecurity = false;
info.Username = "nop_user";
info.Password = "********";
var cs = dataProvider.BuildConnectionString(info);
Defensive patterns

Strategy: validation

Validate before calling

if (connInfo.IntegratedSecurity)
    throw new InvalidOperationException("MySQL provider requires Username/Password; disable IntegratedSecurity.");
// ensure Username/Password set
var cs = dataProvider.BuildConnectionString(connInfo);

Type guard

static bool RequiresSqlAuth(DataProviderType t) => t is DataProviderType.MySql or DataProviderType.PostgreSQL;

Try / catch

try { var cs = dataProvider.BuildConnectionString(connInfo); }
catch (NopException ex) when (ex.Message.Contains("only with login and password"))
{ /* clear IntegratedSecurity, collect Username/Password, rebuild */ }

Prevention

When it happens

Trigger: Installation or configuration passes a connection-info object whose IntegratedSecurity flag is true (e.g., copied from a SQL Server config) while the selected provider is MySQL. The check fires before any connection attempt.

Common situations: Reusing a SQL Server appsettings/install model with IntegratedSecurity=true after switching to MySQL; admin UI checkbox 'Use integrated security' left on; default install template shipping with IntegratedSecurity=true.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/4fc5b859386e0022. Report an issue: GitHub.