Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 998: Database Does Not Exist Fix

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 998 (often shown as "database does not exist in server please") is not a standard SQL Server engine error number in the way that 823 or 18456 are. In practice it appears when a client tool, driver, ORM, reporting layer or migration script tries to open a database on a server instance that does not have a database by that name, or when the connection is pointed at the wrong instance. The fix is to confirm the exact server and database names, verify the database actually exists and is online, and correct the connection string or login default so the client stops asking for a database that is not there.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), Azure Data Studio, or another client that can connect to the instance.
  • An account with permission to view databases on the server (sysadmin, dbcreator, or at least VIEW ANY DATABASE).
  • The exact connection string, DSN, or configuration file the failing application uses.
  • Permission to edit that connection string or the application's configuration.
  • Optional: permission to create a database, in case the database genuinely needs to be restored or created.

Step-by-Step

  1. Read the full error text. Note the server name, instance name, database name and login the message mentions. Error 998 messages usually include the database the client asked for, and that name is the key to the fix. If the message only says "database does not exist in server please", capture the connection string from the application log or configuration file, because the client is not echoing the name back.
  2. Connect to the server and list the databases. In SSMS, connect to the instance named in the error, open a new query window, and run SELECT name, state_desc FROM sys.databases ORDER BY name;. Compare the result with the database name the application is asking for. A database that exists but shows a state other than ONLINE (for example RECOVERY_PENDING, SUSPECT, or RESTORING) will behave like a missing database for many clients.
  3. Check that you are on the right instance. A very common cause is connecting to a different instance than the one that holds the database, especially with named instances such as SERVER\SQLEXPRESS versus the default instance. Run SELECT @@SERVERNAME, SERVERPROPERTY('InstanceName'); on the connection that works and compare it with the server value in the failing application's connection string.
  4. Verify the database is online and accessible. If the database is listed but not ONLINE, investigate why before changing anything: check the SQL Server error log, confirm the data and log files exist at the paths recorded in sys.master_files, and check disk space. If the database is in RESTORING state, a restore or log shipping process may be incomplete.
  5. Check the login's default database. A login whose default database has been dropped or taken offline will fail at connection time with a database-related error. In SSMS, open Security > Logins, open the login's properties, and set the default database to master or to a database that exists. Labels vary slightly by SSMS version, but the Login Properties dialog always includes a Default database setting.
  6. Correct the connection string. In the application configuration, check the Initial Catalog, Database, or DSN database field. It must match the real database name exactly, including spelling, spaces and case where the server collation is case-sensitive. Also confirm the server and instance portion. Save the change and restart the application or its connection pool so the old string is not reused.
  7. Create or restore the database if it is genuinely missing. If the database should exist, restore it from backup or create it with CREATE DATABASE YourDbName;. Creating an empty database only fixes the connection error; the application will still fail if it expects tables and data, so restore from backup where possible. This is a data-affecting step: creating a database is safe, but restoring over an existing database replaces its contents, so confirm the target name before you run it.
  8. Test with a minimal connection. Use the same login and connection string in SSMS or a small test script. If the test succeeds but the application still fails, the application is caching an old connection string, running under a different user, or reading a different configuration file than the one you edited.

Common Mistakes

  • Editing the connection string in the development configuration file while the deployed application reads a different file or an environment variable.
  • Assuming the database is missing when it is actually offline, restoring, or suspect, which produces a similar client-side failure.
  • Connecting to the default instance when the database lives on a named instance, or vice versa.
  • Changing the login's default database but forgetting that the application explicitly sets a database in its connection string, which overrides the login default.
  • Creating an empty database to silence the error and then wondering why the application reports missing tables.
  • Ignoring case sensitivity on servers using a case-sensitive collation, where Sales and sales are different names.

Tips

  • Keep a note of the exact server, instance and database names used in each environment so you can compare them quickly when an error appears.
  • Use SELECT name FROM sys.databases; as your first check every time; it is faster than hunting through the SSMS object explorer.
  • If the error appears after a migration or deployment, compare the connection strings before and after the change rather than starting from scratch.
  • Check the SQL Server error log around the time of the failure; it often records the login attempt and the reason it was rejected.
  • For applications that pool connections, a restart of the application or the pool is often needed before a corrected connection string takes effect.

Troubleshooting

If the database is listed and online but the application still reports that it does not exist, connect using the same login the application uses and run SELECT DB_NAME(); and SELECT SUSER_SNAME();. This confirms which database and login the server actually sees. If the login cannot connect at all, the problem is authentication or permissions rather than a missing database, and the error text will usually mention login failure instead.

If the database name contains spaces or special characters, make sure the connection string quotes or escapes it correctly; an unescaped name can be parsed as a different database. If the server is a named instance and the client uses a port number, confirm the SQL Server Browser service is running or that the port is specified correctly.

If you suspect the database was dropped, check backups and the SQL Server error log for drop events before recreating anything. Recreating a database with the same name does not restore its data, and restoring over an existing database replaces its contents, so take a backup first if the current data matters.

If none of the above resolves it, capture the exact connection string (with the password removed), the full error text, and the output of the sys.databases query, and compare them line by line. The mismatch is almost always visible once the three are side by side.

Frequently Asked Questions

Is error 998 a real SQL Server engine error number?

It is not one of the commonly documented engine errors such as 823 or 18456. In practice it is a client-side or driver-level message meaning the requested database was not found on the server, so treat it as a name, instance, or state mismatch and verify those first.

Why does the error appear when the database exists in SSMS?

The application is usually connecting to a different instance, using a different login with a different default database, or reading an outdated connection string. Confirm the server name and database name in the exact configuration the application loads.

Can an offline database cause this error?

Yes. A database that is offline, restoring, or suspect cannot be opened by clients, and many drivers report it as missing rather than unavailable. Check the state in sys.databases before assuming the database was dropped.

Does changing the login's default database fix it?

Only if the failure happens at connection time because the login's default database is gone. If the application specifies a database in its connection string, that value takes precedence and must be corrected instead.

Will creating an empty database with the right name solve the problem?

It removes the connection error but not the underlying problem if the application needs its tables and data. Restore from backup where possible, and confirm you are creating the database on the correct instance.

What should I check first if this started after a deployment?

Compare the connection string before and after the deployment, then confirm the target server and database still exist and are online. Deployment scripts sometimes point an application at a database name that was only created in a different environment.