Andy0692
Andy0692

Reputation: 35

Unable to attach new database

I am trying to attach a database to my SQL Server 2016. I'm getting the following error - any advice?

Failed to retrieve data for this request.
(Microsoft.SqlServer.Management.Sdk.Sfc)

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

C:\TransportTest.bak is not a primary database file. (Microsoft SQL Server, Error: 5171)

Upvotes: 2

Views: 1656

Answers (3)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28423

A backup(.bak) file is not supposed to be ATTACHED. It's a backup file (not .mdf file) that you have to RESTORE.

RESTORE DATABASE [TransportTest] FROM DISK ='C:\TransportTest.bak'

Also you can use try some alternative as mentioned here, in case of issue with .mdf files

Upvotes: 0

Ivo Gjorgjievski
Ivo Gjorgjievski

Reputation: 129

You should attach database file with .mdf extension.

SQL Server database has two operating system files: a data file and a log file. Data files contain data and objects such as tables, indexes, stored procedures, and views. Every database has one primary data file. The recommended file name extension for primary data files is .mdf

https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-files-and-filegroups?view=sql-server-ver15

Upvotes: -1

MintBerryCRUNCH
MintBerryCRUNCH

Reputation: 551

You are trying to add a .bak file, .bak files need to be restored and not attached.

enter image description here

Upvotes: 2

Related Questions