{"record":{"id":"ec0cd0d535399988","repo":"nopSolutions/nopCommerce","slug":"unable-to-connect-to-the-new-database-please-try","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/MsSqlDataProvider.cs","lineNumber":86,"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                break;\n        }\n    }\n\n    /// <summary>\n    /// Checks if the specified database exists, returns true if database exists\n    /// </summary>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the returns true if the database exists.\n    /// </returns>\n    public virtual async Task<bool> DatabaseExistsAsync()\n    {\n        try","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/DataProviders/MsSqlDataProvider.cs#L68-L104","documentation":"Thrown at the end of MsSqlDataProvider.CreateDatabase when the freshly-created SQL Server database cannot be reached within the allotted retry window. After issuing CREATE DATABASE the method polls DatabaseExists() up to 'triesToConnect' times, sleeping 1 second between attempts; if the DB is still unreachable on the final iteration it throws a bare Exception, aborting the nopCommerce installation.","triggerScenarios":"Installation flow calling dataProvider.CreateDatabase(databaseName, triesToConnect) where the SQL Server instance is slow to materialize the new database, the SQL Server service is under load, disk I/O is saturated, or the connection string points at a server that cannot authenticate/open the new catalog in time.","commonSituations":"Shared hosting where CREATE DATABASE is throttled; SQL Server Express with slow spinning disks; low triesToConnect default; wrong server name/credentials making DatabaseExists always return false; firewall blocking port 1433 so the DB is never reachable.","solutions":["Increase the triesToConnect value passed to CreateDatabase so the loop tolerates slow provisioning.","Verify the SQL Server instance is up and the account can connect to the 'master' database (test with DatabaseExists before installing).","Check the server name, port, and credentials in the install connection string; confirm port 1433/firewall allows the app host.","Pre-create the database manually and re-run installation, or simply retry the installer once the server is responsive."],"exampleFix":"// before\ndataProvider.CreateDatabase(dbName, triesToConnect: 5);\n\n// after\ndataProvider.CreateDatabase(dbName, triesToConnect: 30);","handlingStrategy":"retry","validationCode":"// Pre-flight: confirm server reachable and creds valid before install\nif (!dataProvider.DatabaseExists())\n    throw new InvalidOperationException(\"Cannot reach SQL Server; check connection string before creating the database.\");","typeGuard":null,"tryCatchPattern":"try { dataProvider.CreateDatabase(dbName, triesToConnect: 30); }\ncatch (Exception ex) when (ex.Message.Contains(\"Unable to connect to the new database\"))\n{ /* log, verify server/creds/port 1433, then retry install once server is responsive */ }","preventionTips":["Test the connection to 'master' and verify CREATE DATABASE permission before installing.","Use a generous triesToConnect on slow/shared hosting.","Confirm port 1433/firewall egress from the app host."],"tags":["database","sqlserver","installation","retry","network","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}