{"record":{"id":"93d0f9b0145e09e9","repo":"nopSolutions/nopCommerce","slug":"unable-to-connect-to-the-new-database-please-try-93d0f9","errorCode":null,"errorMessage":"Unable to connect to the new database. Please try one more time","messagePattern":"Unable to connect to the new database\\. Please try one more time","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Data/DataProviders/PostgreSqlDataProvider.cs","lineNumber":154,"sourceCode":"            var command = connection.CreateCommand();\n            command.CommandText = query;\n            command.Connection.Open();\n\n            command.ExecuteNonQuery();\n        }\n\n        //try connect\n        if (triesToConnect <= 0)\n            return;\n\n        //sometimes on slow servers (hosting) there could be situations when database requires some time to be created.\n        //but we have already started creation of tables and sample data.\n        //as a result there is an exception thrown and the installation process cannot continue.\n        //that's why we are in a cycle of \"triesToConnect\" times trying to connect to a database with a delay of one second.\n        for (var i = 0; i <= triesToConnect; i++)\n        {\n            if (i == triesToConnect)\n                throw new Exception(\"Unable to connect to the new database. Please try one more time\");\n\n            if (!DatabaseExists())\n                Thread.Sleep(1000);\n            else\n            {\n                builder.Database = databaseName;\n                using var connection = GetInternalDbConnection(builder.ConnectionString) as NpgsqlConnection;\n                var command = connection.CreateCommand();\n                command.CommandText = \"CREATE EXTENSION IF NOT EXISTS citext; CREATE EXTENSION IF NOT EXISTS pgcrypto;\";\n                command.Connection.Open();\n                command.ExecuteNonQuery();\n                connection.ReloadTypes();\n\n                break;\n            }\n        }\n    }\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/DataProviders/PostgreSqlDataProvider.cs#L136-L172","documentation":"PostgreSqlDataProvider.CreateDatabase retries DatabaseExists() up to triesToConnect times (1s apart) after issuing CREATE DATABASE; if the new database is still not connectable on the final attempt it throws a bare Exception. On success it additionally installs the citext and pgcrypto extensions. This blocks the nopCommerce installer.","triggerScenarios":"Installation calls dataProvider.CreateDatabase(databaseName, triesToConnect) against PostgreSQL where the server is slow to make the new database connectable, or where the role lacks permission to create/connect, within the retry budget.","commonSituations":"PostgreSQL on constrained hosting with provisioning lag; role without CREATEDB/CONNECT privileges so DatabaseExists always fails; missing citext/pgcrypto extensions and the role cannot CREATE EXTENSION; wrong host/port/firewall blocking 5432.","solutions":["Increase triesToConnect so the poll loop tolerates slower provisioning.","Verify the PostgreSQL role has CREATEDB and CONNECT privileges and that citext/pgcrypto are available/installable.","Confirm host, port 5432 reachability, and credentials; test an external psql connect first.","Pre-create the database and the citext/pgcrypto extensions manually, then run installation."],"exampleFix":"// before\ndataProvider.CreateDatabase(dbName, triesToConnect: 5);\n\n// after\ndataProvider.CreateDatabase(dbName, triesToConnect: 30);","handlingStrategy":"retry","validationCode":"// Pre-flight: confirm PostgreSQL reachable and role can connect\nif (!dataProvider.DatabaseExists())\n    throw new InvalidOperationException(\"Cannot reach PostgreSQL; check connection string and role privileges.\");","typeGuard":null,"tryCatchPattern":"try { dataProvider.CreateDatabase(dbName, triesToConnect: 30); }\ncatch (Exception ex) when (ex.Message.Contains(\"Unable to connect to the new database\"))\n{ /* verify role CREATEDB/CONNECT, citext/pgcrypto availability, port 5432, then retry */ }","preventionTips":["Confirm the role has CREATEDB/CONNECT and can CREATE EXTENSION citext, pgcrypto.","Use a generous triesToConnect on slow hosting.","Pre-create the database and extensions manually if provisioning is unreliable."],"tags":["database","postgresql","installation","retry","network","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}