移动 tempDB 后无法连接到我的 SQL Management Studio

Aid*_*den 2 sql-server sql-server-2012 tempdb

在这里处于相当不利的位置。今天下午在我的 tempDB 上,我运行了以下查询: sp_helpfile找到我的 MDF 和 LOG 文件所在的位置。我的 MDF 在我的 C: 驱动器上,而我的 LOG 文件在 D: 驱动器上,所以我运行了以下查询以将此日志文件从 D: 驱动器移回 C: 驱动器。(这可能不是我运行的确切查询,因为我不记得它到底是什么!)

use master

go

Alter database tempdb modify file (name = templog, filename = 'C:[drivelocation]\tempdb.ldf')

go
Run Code Online (Sandbox Code Playgroud)

运行后,我关闭了 SQL Server MS 2012 并重新打开以连接回我机器上的 SQL Server。尝试登录时,SQL MS 返回以下错误:

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

Cannot connect to machineName\SQL2012.

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

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476

------------------------------
Error Number: 2
Severity: 20
State: 0


------------------------------
Program Location:

at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

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

The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)

显然,它似乎再也找不到文件了!我什至尝试在服务管理器中启动该服务,但这表明 Windows 无法启动该服务,错误代码为 1814。即使重新启动机器也无法使其工作。

无论如何,我可以解决这个问题吗?我一直在尝试查看是否可以通过 CMD 再次将日志文件位置更改回 D: 驱动器,但似乎找不到任何内容

编辑 我在尝试启动服务时在事件查看器中注意到了这个警告:

Could not create tempdb. You may not have enough disk space available. Free additional disk space by deleting other files on the tempdb drive and then restart SQL Server. Check for additional errors in the event log that may indicate why the tempdb files could not be initialized.
Run Code Online (Sandbox Code Playgroud)

这不会加起来,因为 C: DRIVE 上至少有 250GB 可用空间

编辑 2

根据要求,这是我的错误日志

2019-11-01 22:37:06.45 Server      Microsoft SQL Server 2012 (SP4-GDR) (KB4057116) - 11.0.7462.6 (X64) 
    Jan  5 2018 22:11:56 
    Copyright (c) Microsoft Corporation
    Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 17763: )

2019-11-01 22:37:06.45 Server      (c) Microsoft Corporation.
2019-11-01 22:37:06.45 Server      All rights reserved.
2019-11-01 22:37:06.45 Server      Server process ID is 20460.
2019-11-01 22:37:06.45 Server      System Manufacturer: 'Dell Inc.', System Model: 'Precision Tower 7910'.
2019-11-01 22:37:06.45 Server      Authentication mode is MIXED.
2019-11-01 22:37:06.45 Server      Logging SQL Server messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Log\ERRORLOG'.
2019-11-01 22:37:06.45 Server      The service account is 'MACHINENAMEREMOVED'. This is an informational message; no user action is required.
2019-11-01 22:37:06.45 Server      Registry startup parameters: 
     -d C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\master.mdf
     -e C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Log\ERRORLOG
     -l C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\mastlog.ldf
2019-11-01 22:37:06.45 Server      Command Line Startup Parameters:
     -s "SQL2012"
2019-11-01 22:37:06.67 Server      SQL Server detected 1 sockets with 10 cores per socket and 20 logical processors per socket, 20 total logical processors; using 20 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2019-11-01 22:37:06.67 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2019-11-01 22:37:06.67 Server      Detected 32690 MB of RAM. This is an informational message; no user action is required.
2019-11-01 22:37:06.67 Server      Using locked pages in the memory manager.
2019-11-01 22:37:06.70 Server      Large Page Allocated: 32MB 
2019-11-01 22:37:06.91 Server      This instance of SQL Server last reported using a process ID of 17484 at 01/11/2019 22:25:55 (local) 01/11/2019 22:25:55 (UTC). This is an informational message only; no user action is required.
2019-11-01 22:37:06.92 Server      Node configuration: node 0: CPU mask: 0x00000000000fffff:0 Active CPU mask: 0x00000000000fffff:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2019-11-01 22:37:07.00 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2019-11-01 22:37:07.00 Server      Lock partitioning is enabled.  This is an informational message only. No user action is required.
2019-11-01 22:37:07.00 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
2019-11-01 22:37:07.00 Server      Software Usage Metrics is disabled.
2019-11-01 22:37:07.01 spid5s      Starting up database 'master'.
2019-11-01 22:37:07.02 spid5s      9 transactions rolled forward in database 'master' (1:0). This is an informational message only. No user action is required.
2019-11-01 22:37:07.02 spid5s      0 transactions rolled back in database 'master' (1:0). This is an informational message only. No user action is required.
2019-11-01 22:37:07.05 Server      CLR version v4.0.30319 loaded.
2019-11-01 22:37:07.11 spid5s      Resource governor reconfiguration succeeded.
2019-11-01 22:37:07.11 spid5s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2019-11-01 22:37:07.11 spid5s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2019-11-01 22:37:07.12 Server      Common language runtime (CLR) functionality initialized using CLR version v4.0.30319 from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\.
2019-11-01 22:37:07.14 spid5s      SQL Trace ID 1 was started by login "sa".
2019-11-01 22:37:07.14 spid5s      Server name is 'machine\SQL2012'. This is an informational message only. No user action is required.
2019-11-01 22:37:07.16 spid13s     The certificate [Cert Hash(sha1) "3605E5C22E9EA14834F0C8069ED7EFE9437F6DA0"] was successfully loaded for encryption.
2019-11-01 22:37:07.16 spid5s      Failed to verify Authenticode signature on DLL 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\Binn\ftimport.dll'.
2019-11-01 22:37:07.16 spid5s      Starting up database 'msdb'.
2019-11-01 22:37:07.16 spid9s      Starting up database 'mssqlsystemresource'.
2019-11-01 22:37:07.16 spid13s     Server is listening on [ 'any' <ipv6> 58026].
2019-11-01 22:37:07.16 spid13s     Server is listening on [ 'any' <ipv4> 58026].
2019-11-01 22:37:07.16 spid13s     Server local connection provider is ready to accept connection on [ \\.\pipe\SQLLocal\SQL2012 ].
2019-11-01 22:37:07.16 spid13s     Server named pipe provider is ready to accept connection on [ \\.\pipe\MSSQL$SQL2012\sql\query ].
2019-11-01 22:37:07.16 Server      Server is listening on [ ::1 <ipv6> 58027].
2019-11-01 22:37:07.16 Server      Server is listening on [ 127.0.0.1 <ipv4> 58027].
2019-11-01 22:37:07.16 Server      Dedicated admin connection support was established for listening locally on port 58027.
2019-11-01 22:37:07.16 spid9s      The resource database build version is 11.00.7462. This is an informational message only. No user action is required.
2019-11-01 22:37:07.17 spid13s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2019-11-01 22:37:07.17 Server      SQL Server is attempting to register a Service Principal Name (SPN) for the SQL Server service. Kerberos authentication will not be possible until a SPN is registered for the SQL Server service. This is an informational message. No user action is required.
2019-11-01 22:37:07.18 spid9s      Starting up database 'model'.
2019-11-01 22:37:07.19 spid5s      1 transactions rolled forward in database 'msdb' (4:0). This is an informational message only. No user action is required.
2019-11-01 22:37:07.19 spid5s      0 transactions rolled back in database 'msdb' (4:0). This is an informational message only. No user action is required.
2019-11-01 22:37:07.20 Server      The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/BDTUK178AA.bluedoor.local:SQL2012 ] for the SQL Server service. Windows return code: 0x200b, state: 15. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.
2019-11-01 22:37:07.20 Server      The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/machine ] for the SQL Server service. Windows return code: 0x200b, state: 15. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.
2019-11-01 22:37:07.20 spid9s      Clearing tempdb database.
2019-11-01 22:37:07.23 spid9s      Error: 5171, Severity: 16, State: 1.
2019-11-01 22:37:07.23 spid9s      C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\tempdb.mdf is not a primary database file.
2019-11-01 22:37:07.23 spid9s      Error: 1802, Severity: 16, State: 4.
2019-11-01 22:37:07.23 spid9s      CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
2019-11-01 22:37:07.23 spid9s      Could not create tempdb. You may not have enough disk space available. Free additional disk space by deleting other files on the tempdb drive and then restart SQL Server. Check for additional errors in the event log that may indicate why the tempdb files could not be initialized.
2019-11-01 22:37:07.23 spid9s      SQL Server shutdown has been initiated
2019-11-01 22:37:07.23 spid9s      SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
Run Code Online (Sandbox Code Playgroud)

AMt*_*two 5

请注意您引用的错误消息的最后一部分:

.. Check for additional errors in the event log that may indicate why the tempdb files could not be initialized.
Run Code Online (Sandbox Code Playgroud)

如果您查看与 tempdb 创建相关的整个错误块:

2019-11-01 22:37:07.20 spid9s      Clearing tempdb database.
2019-11-01 22:37:07.23 spid9s      Error: 5171, Severity: 16, State: 1.
2019-11-01 22:37:07.23 spid9s      C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\tempdb.mdf is not a primary database file.
2019-11-01 22:37:07.23 spid9s      Error: 1802, Severity: 16, State: 4.
2019-11-01 22:37:07.23 spid9s      CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
2019-11-01 22:37:07.23 spid9s      Could not create tempdb. You may not have enough disk space available. Free additional disk space by deleting other files on the tempdb drive and then restart SQL Server. Check for additional errors in the event log that may indicate why the tempdb files could not be initialized.
Run Code Online (Sandbox Code Playgroud)

一个错误似乎可能是问题所在:

...\tempdb.mdf is not a primary database file.
Run Code Online (Sandbox Code Playgroud)

您应该尝试删除该tempdb.mdf文件,然后重新启动 SQL Server 服务。当您在那里时,检查是否有tempdb.ldf文件并删除该文件。如果 tempdb 数据文件尚不存在,SQL Server 将重新创建它们。