I can't create a Database after I uninstalled SQL Server and then reinstalled SQL Server

All we need is an easy explanation of the problem, so here it is.

I uninstalled SQL Server and then reinstalled SQL Server on my laptop and now when I try to create an old database from my first installation called ‘SSIS’ and I get the following error:

Msg 5170, Level 16, State 4, Line 1
Cannot create file ‘C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SSIS.mdf’ because it already exists. Change the file path or the file name, and retry the operation.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

When I try to access the "DATA" folder I can’t.

I can create other databases but not the one named "SSIS" I’ve searched online and others have had similar errors but their fixes did NOT work for my laptop.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

It seems that the database files for the SSIS database have remained in place after the uninstall. I believe user database files are not deleted by the uninstall process (presumably by design) and as others have said you need to delete the file, or create the new database in another location

You should be able to delete the file from an administrative Powershell prompt using

Remove-Item "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SSIS.mdf" -Force

You will possibly find the same issue with the log file so may need to run

Remove-Item "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\LOG\SSIS_log.ldf" -Force

(assuming the path / filename is correct)

Method 2

A SQL Server database consists of data files .mdf and a log file .ldf

The paths to these files are specified when creating a database:

I can't create a Database after I uninstalled SQL Server and then reinstalled SQL Server

The error you get means that a data file with that name already exists.

If this file is not used by any database, then you can just remove it.

If used – please specify other paths or names for the database files when creating a database.

That the following directory C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA is created by SQL Server and users do not have access to it. To get access to this directory run Explorer as administrator.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply