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?
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
andSELECT * FROM master.sys.master_files
to see more of what SQL thinks is going on. – BillP3rd – 2016-01-30T20:23:48.843You might also do
DBCC CHECKDB
in the[master]
database to see if it detects any inconsistencies. – BillP3rd – 2016-01-30T20:42:31.523