{"record":{"id":"9c897cbee71948e2","repo":"nopSolutions/nopCommerce","slug":"data-provider-supports-connection-only-with-login-9c897c","errorCode":null,"errorMessage":"Data provider supports connection only with login and password","messagePattern":"Data provider supports connection only with login and password","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Data/DataProviders/PostgreSqlDataProvider.cs","lineNumber":371,"sourceCode":"    public virtual async Task<long> GetDatabaseSizeAsync()\n    {\n        using var currentConnection = CreateDataConnection();\n        var result = await currentConnection.QueryToListAsync<long>($\"SELECT pg_database_size('{GetConnectionStringBuilder().Database}') / 1024 as sizebytes\");\n\n        return result.FirstOrDefault();\n    }\n\n    /// <summary>\n    /// Build the connection string\n    /// </summary>\n    /// <param name=\"nopConnectionString\">Connection string info</param>\n    /// <returns>Connection string</returns>\n    public virtual string BuildConnectionString(INopConnectionStringInfo nopConnectionString)\n    {\n        ArgumentNullException.ThrowIfNull(nopConnectionString);\n\n        if (nopConnectionString.IntegratedSecurity)\n            throw new NopException(\"Data provider supports connection only with login and password\");\n\n        var builder = new NpgsqlConnectionStringBuilder\n        {\n            Host = nopConnectionString.ServerName,\n            //Cast DatabaseName to lowercase to avoid case-sensitivity problems\n            Database = nopConnectionString.DatabaseName.ToLowerInvariant(),\n            Username = nopConnectionString.Username,\n            Password = nopConnectionString.Password,\n        };\n\n        return builder.ConnectionString;\n    }\n\n    /// <summary>\n    /// Gets the name of a foreign key\n    /// </summary>\n    /// <param name=\"foreignTable\">Foreign key table</param>\n    /// <param name=\"foreignColumn\">Foreign key column name</param>","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/DataProviders/PostgreSqlDataProvider.cs#L353-L389","documentation":"PostgreSqlDataProvider.BuildConnectionString throws NopException when INopConnectionStringInfo.IntegratedSecurity is true. The Npgsql provider in nopCommerce is configured for username/password auth only; there is no SSPI/Windows-auth path, so IntegratedSecurity is rejected before the NpgsqlConnectionStringBuilder is built.","triggerScenarios":"Install/configuration supplies IntegratedSecurity=true for a PostgreSQL connection (commonly inherited from a SQL Server template). The guard fires before connection construction.","commonSituations":"Switching provider from SQL Server to PostgreSQL without clearing the integrated-security flag; default install model with IntegratedSecurity=true; admin UI checkbox left enabled.","solutions":["Set IntegratedSecurity=false and provide Username and Password.","When migrating providers, regenerate the connection configuration rather than reusing the SQL Server one.","Validate the IntegratedSecurity flag against the selected provider during install."],"exampleFix":"// before\ninfo.IntegratedSecurity = true; // from SQL Server template\nvar cs = dataProvider.BuildConnectionString(info);\n\n// after\ninfo.IntegratedSecurity = false;\ninfo.Username = \"nop_user\";\ninfo.Password = \"********\";\nvar cs = dataProvider.BuildConnectionString(info);","handlingStrategy":"validation","validationCode":"if (connInfo.IntegratedSecurity)\n    throw new InvalidOperationException(\"PostgreSQL provider requires Username/Password; disable IntegratedSecurity.\");\nvar cs = dataProvider.BuildConnectionString(connInfo);","typeGuard":"static bool RequiresSqlAuth(DataProviderType t) => t is DataProviderType.MySql or DataProviderType.PostgreSQL;","tryCatchPattern":"try { var cs = dataProvider.BuildConnectionString(connInfo); }\ncatch (NopException ex) when (ex.Message.Contains(\"only with login and password\"))\n{ /* clear IntegratedSecurity, provide Username/Password, rebuild */ }","preventionTips":["Do not carry IntegratedSecurity=true over from SQL Server configs.","Always supply Username/Password for PostgreSQL.","Validate IntegratedSecurity against provider type during install."],"tags":["database","postgresql","configuration","connection-string","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}