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

Troubleshooting Guide: SQL Server Error 3901 — “The transaction name must be specified when it is used with the mark option”

Why This Error Happens

This error occurs when a BEGIN TRANSACTION statement includes the WITH MARK option but omits the required transaction name. SQL Server mandates a named transaction when using WITH MARK because the name is stored in the msdb log history and is required for point-in-time recovery operations. This is typically caused by a malformed Transact-SQL script, a legacy application template, or a copy-paste error in a stored procedure or migration script.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Script or Procedure

  • Review the SQL Server error log or SSMS output pane to locate the exact batch that triggered Error 3901.
  • Check recently deployed stored procedures, SSIS packages, or scheduled Agent jobs for BEGIN TRANSACTION ... WITH MARK syntax.
  • Use sp_helptext on suspect stored procedures to inspect the raw transaction syntax.

Step 2: Correct the Transaction Syntax

  • Edit the script to include a quoted transaction name immediately before the WITH MARK clause.
  • Example of the corrected syntax:
  BEGIN TRANSACTION MyNamedTransaction WITH MARK 'Description of transaction purpose';
  • Ensure the transaction name does not exceed 32 characters, as SQL Server truncates or rejects longer names in some contexts.
  • Avoid using reserved keywords or special characters in the transaction name.

Step 3: Validate Dependent Jobs and Automation Scripts

  • Search SQL Server Agent job steps under SQL Server Agent > Jobs in SSMS for any legacy scripts using WITH MARK.
  • Check PowerShell or sqlcmd-based deployment scripts stored in C:\Scripts\ or your CI/CD pipeline repository for the same syntax issue.
  • Update version-controlled .sql files in source control (e.g., Git, Azure DevOps) to prevent the error from reappearing on next deployment.

Step 4: Redeploy and Test in a Non-Production Environment

  • Apply the corrected script to a test instance of SQL Server 2025 running on Windows Server 2025 or Windows 11 first.
  • Execute the transaction manually in SSMS to confirm no syntax errors are returned.
  • Promote the fix to production only after successful validation.

Alternative or Verification Steps

  • Run SELECT * FROM msdb.dbo.logmarkhistory WHERE name = 'MyNamedTransaction'; to confirm the named mark was successfully logged after the fix.
  • If the error persists, remove the WITH MARK clause entirely (if point-in-time marking isn’t strictly required) and use a standard BEGIN TRANSACTION MyNamedTransaction; statement as a quick workaround.