gpt4 book ai didi

sql-server - 无法在 SSMS 中附加数据库

转载 作者:行者123 更新时间:2023-12-04 15:32:35 26 4
gpt4 key购买 nike

对于我的家庭作业,我被告知要下载一个包含 .mdf 的 zip 文件夹。我将要处理的数据库文件。所以我提取了文件并保存了它。然后我进入 SSMS 去附加数据库,我收到了这个错误?

===================================

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)

我只下载了一个 .mdf 文件,没有日志文件。然而,当我尝试附加时,有人告诉我,如果没有日志文件,则会自动创建一个。在这张照片中,它看起来像什么? enter image description here

最佳答案

有两种选择可以做到这一点:

  • 附加 mdf 文件时,在底部 Pane 中,选择 LDF 文件并将其删除,然后选择“确定”。将附加数据库。 Reference

  • Removing LDF file
  • 您可以使用 TSQL 附加数据库。

  • USE [master]
    GO
    CREATE DATABASE [PR] ON
    ( FILENAME = N'C:\Users\Public\Documents\Databases\PR.mdf' )
    FOR ATTACH_REBUILD_LOG
    GO

    关于sql-server - 无法在 SSMS 中附加数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60879311/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com