Remove all references to removed Sql Server database

0

One of my programs that I have written, creates on installation a SQL Server database. The database name is hardcoded in the sources. Now I have the problem, that on a clients machine the program was de-installed and the database was deleted manually (all I know is that the MDF file not more exists). And at re-installation we get a SQL Server error "Database already exists".

All files are removed and also in SQL Management Studio the database is not more visible. I tried to create a new database with the same name in SQL Management Studio and I get the same error.

In the next version of my program I will make the db name configurable. But what can I do meanwhile, to remove any existing link / reference to the broken / wrongly removed database?

StefanG

Posted 2016-01-30T12:03:08.307

Reputation: 111

If you try SELECT name,filename FROM master.sys.sysdatabases, does your "deleted" database appear in the list? – BillP3rd – 2016-01-30T14:43:45.300

@BillP3rd : Yes, it does!!! So I deleted it, and now it does not appear anymore. But the original error remains. What can I do next? – StefanG – 2016-01-30T16:18:05.653

Where all does your installation process you built reference the DB that it's finding as already existing? If it's not in the ODBC entries (per below answer) or on a locally installed SQL instance, then it's in the registry or where ever your installation logic/code is doing that check so to get an accurate answer, check your code at the installation package level, & then remove that reference that causes this installation error. I assume your process DOES not try to create a new DB on a remote SQL Server instance where multiple clients connect as that could be an issue with a shared SQL DB. – Pimp Juice IT – 2016-01-30T17:22:15.663

First, what command(s) did you use to delete the database? Did you do it within SQL or just delete the files from the file system? The "standard" way to force a database to be dropped is:

ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [YourDatabaseName];

I would also suggest SELECT * FROM sys.databases and SELECT * FROM master.sys.master_files to see more of what SQL thinks is going on. – BillP3rd – 2016-01-30T20:23:48.843

You might also do DBCC CHECKDB in the [master] database to see if it detects any inconsistencies. – BillP3rd – 2016-01-30T20:42:31.523

Answers

1

Check for and delete any references to your database from the ODBC Data Sources Administrator control panel.

I'm not sure if your source will be in the 32-bit or 64-bit settings. Depending on your database source you may only be able to delete it from the 32-bit or 64-bit control panels.

To launch the 32-bit control panel right-click your start button, then click "run" and enter:

%systemdrive%\Windows\SysWoW64\Odbcad32.exe

For 64-bit:

%systemdrive%\Windows\System32\Odbcad32.exe

Alternatively you can find them in the (old) Control Panel under Administrative Tools.

Locations for ODBC Data Source Administrator according to this page.

Mokubai

Posted 2016-01-30T12:03:08.307

Reputation: 64 434