nopSolutions/nopCommerce · critical · Exception

Unable to connect to the new database. Please try one more…

Error message

Unable to connect to the new database. Please try one more time

What it means

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.

Solutions

  1. Increase triesToConnect so the poll loop tolerates slower provisioning.
  2. Verify the PostgreSQL role has CREATEDB and CONNECT privileges and that citext/pgcrypto are available/installable.
  3. Confirm host, port 5432 reachability, and credentials; test an external psql connect first.
  4. Pre-create the database and the citext/pgcrypto extensions manually, then run installation.

Example fix

// before
dataProvider.CreateDatabase(dbName, triesToConnect: 5);

// after
dataProvider.CreateDatabase(dbName, triesToConnect: 30);
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight: confirm PostgreSQL reachable and role can connect
if (!dataProvider.DatabaseExists())
    throw new InvalidOperationException("Cannot reach PostgreSQL; check connection string and role privileges.");

Try / catch

try { dataProvider.CreateDatabase(dbName, triesToConnect: 30); }
catch (Exception ex) when (ex.Message.Contains("Unable to connect to the new database"))
{ /* verify role CREATEDB/CONNECT, citext/pgcrypto availability, port 5432, then retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at src/Libraries/Nop.Data/DataProviders/PostgreSqlDataProvider.cs:154

            var command = connection.CreateCommand();
            command.CommandText = query;
            command.Connection.Open();

            command.ExecuteNonQuery();
        }

        //try connect
        if (triesToConnect <= 0)
            return;

        //sometimes on slow servers (hosting) there could be situations when database requires some time to be created.
        //but we have already started creation of tables and sample data.
        //as a result there is an exception thrown and the installation process cannot continue.
        //that's why we are in a cycle of "triesToConnect" times trying to connect to a database with a delay of one second.
        for (var i = 0; i <= triesToConnect; i++)
        {
            if (i == triesToConnect)
                throw new Exception("Unable to connect to the new database. Please try one more time");

            if (!DatabaseExists())
                Thread.Sleep(1000);
            else
            {
                builder.Database = databaseName;
                using var connection = GetInternalDbConnection(builder.ConnectionString) as NpgsqlConnection;
                var command = connection.CreateCommand();
                command.CommandText = "CREATE EXTENSION IF NOT EXISTS citext; CREATE EXTENSION IF NOT EXISTS pgcrypto;";
                command.Connection.Open();
                command.ExecuteNonQuery();
                connection.ReloadTypes();

                break;
            }
        }
    }

View on GitHub (pinned to 64bdf2ff08)