For my homework assignment I'm told to download a zip folder holding a .mdf file for the database I'm going to be working on. So I extracted the file and saved it. I then went into SSMS went to attach the database and I got this error?
===================================
Attach database failed for Server 'DESKTOP-VDSUPUV\SQLEXPRESS'. (Microsoft.SqlServer.Smo)
------------------------------
For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18206.0+((SSMS_Rel).191029-2112)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
at Microsoft.SqlServer.Management.SqlManagerUI.AttachDatabaseData.PrimaryFile.Attach()
at Microsoft.SqlServer.Management.SqlManagerUI.AttachDatabase.SendDataToServer()
===================================
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType, Boolean retry)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries, Boolean retry)
at Microsoft.SqlServer.Management.Smo.Server.AttachDatabaseWorker(String name, StringCollection files, String owner, AttachOptions attachOptions)
at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
===================================
Unable to open the physical file "C:\Users\Public\Documents\Databases\PR_log.ldf". Operating system error 2: "2(The system cannot find the file specified.)".
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (.Net SqlClient Data Provider)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=13.00.5026&EvtSrc=MSSQLServer&EvtID=5120&LinkId=20476
------------------------------
Server Name: DESKTOP-VDSUPUV\SQLEXPRESS
Error Number: 5120
Severity: 16
State: 101
Line Number: 1
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
I downloaded only one .mdf file there is no log file. I was told however when I try to attach,if there isn't a log file then one is created automatically. In this pic that's what it looks like?
There are two options to do this:

USE [master]
GO
CREATE DATABASE [PR] ON
( FILENAME = N'C:\Users\Public\Documents\Databases\PR.mdf' )
FOR ATTACH_REBUILD_LOG
GO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With