How to fix Error 12513 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 12513 – Internal Error While Cloning Table in SQL Server 2025

Why This Error Happens

Error 12513 typically occurs when SQL Server’s internal table cloning operation (used for schema-only copy operations via sp_clone_database or similar DDL cloning utilities) encounters a mismatch between metadata and the underlying data files. This is often caused by insufficient permissions on the target directory, a corrupted or locked source table file, or an interrupted previous clone operation that left temporary system objects in an inconsistent state. In some cases, this also surfaces when the SQL Server service account lacks write access to the destination path specified during the clone request.

Step-by-Step Resolution Guide

Step 1: Verify Service Account Permissions

  • Open Services.msc on Windows Server 2025 / Windows 11 and locate the SQL Server (MSSQLSERVER) service.
  • Confirm the “Log On As” account has Full Control on both the source database directory and the target clone directory (typically C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\).
  • Run the following command in an elevated PowerShell window to grant permissions if missing:
  icacls "C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA" /grant "NT SERVICE\MSSQLSERVER":(OI)(CI)F

Step 2: Clear Orphaned Clone Metadata

  • Open SQL Server Management Studio (SSMS) and connect to the instance via a query window.
  • Run the following to check for incomplete clone sessions:
  SELECT * FROM sys.dm_exec_requests WHERE command LIKE '%CLONE%';
  • If a stuck session is found, terminate it using KILL <session_id>; and retry the clone operation.

Step 3: Validate Table Consistency

  • Run DBCC CHECKTABLE('YourTableName') WITH NO_INFOMSGS, ALL_ERRORMSGS; to rule out underlying corruption.
  • If corruption is detected, restore the table from the most recent clean backup before attempting the clone again.

Step 4: Restart SQL Server Service and Clear TempDB Cache

  • In an elevated PowerShell prompt, restart the instance:
  Restart-Service -Name 'MSSQLSERVER' -Force
  • This clears any residual locks in tempdb that may be blocking the internal clone engine from allocating new metadata structures.

Alternative or Verification Steps

  • After applying the fixes, re-run the original CLONE DATABASE or sp_clone_database command and confirm Error 12513 no longer appears in the SQL Server Error Log (ERRORLOG file located in the MSSQL\LOG folder).
  • As an alternative, if cloning still fails, perform a manual schema-only export using SQL Server Generate Scripts Wizard and import it into a new empty database to bypass the internal cloning engine entirely.