Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1041: Option Not Allowed for a Log

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Error 1041 in SQL Server means you tried to apply an option to a transaction log file that is only valid for data files. The fix is to remove that option from the log file's specification and apply it only to the data file (or leave it out entirely). You cannot set file growth, maximum size, or other filegroup-specific attributes on a log file in the way you might expect; log files have their own limited set of allowed options. The exact wording of the error is typically: "Option '%ls' is not allowed for a log." The practical resolution is to correct your CREATE DATABASE, ALTER DATABASE, or backup/restore statement so that log files are defined with only the options SQL Server permits for them.

What You'll Need

  • Access to SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, connected with an account that can create or alter the database (dbcreator or sysadmin).
  • The original statement or script that produced the error, so you can see which option was applied to the log file.
  • Permission to view the current file definitions: you can run SELECT name, type_desc, physical_name, size, max_size, growth, is_percent_growth FROM sys.database_files; in the affected database.
  • A backup of the database if you are modifying an existing one, since file changes can affect recovery.

Step-by-Step

  1. Read the full error message. Error 1041 usually names the option that was rejected, for example FILEGROWTH, MAXSIZE, or a filegroup-related clause. Note the exact option and the file it was applied to.
  2. Locate the statement that caused it. Common sources are a CREATE DATABASE statement with a LOG ON clause, an ALTER DATABASE ... MODIFY FILE statement, or a restore operation that includes file relocation. Open the script and find the section that defines the log file (the part after LOG ON or the MODIFY FILE block with NAME = N'..._log').
  3. Identify the disallowed option. In SQL Server, log files support a narrower set of file options than data files. Options such as FILEGROUP, MAXSIZE in some contexts, and certain growth settings may be rejected when applied to a log. Check the line where the option appears next to the log file definition.
  4. Remove or move the option. If the option belongs on the data file, move it to the ON clause for the data file. If it does not belong anywhere (for example, a filegroup assignment on a log), delete it. Log files cannot be members of a filegroup; they exist independently.
  5. Rewrite the log file definition correctly. A minimal, valid log file clause looks like:
    LOG ON (NAME = N'MyDb_log', FILENAME = N'C:\SQLData\MyDb_log.ldf', SIZE = 64MB, FILEGROWTH = 64MB);
    Notice there is no FILEGROUP and no MAXSIZE unless you are certain it is permitted in your version and context. Keep the options to the essentials: name, filename, size, and growth.
  6. Apply the corrected statement. Run the fixed CREATE DATABASE or ALTER DATABASE statement. If you are altering an existing database, use ALTER DATABASE MyDb MODIFY FILE (NAME = N'MyDb_log', FILEGROWTH = 64MB); with only the options that are valid for a log.
  7. Verify the change. Query sys.database_files again to confirm the log file now has the intended settings and no errors occurred. Check the SQL Server error log for any related messages.
  8. If the error came from a restore, adjust the RESTORE statement. Use RESTORE DATABASE ... WITH MOVE 'LogicalLogName' TO 'C:\SQLData\MyDb_log.ldf'; and avoid adding file options that are not allowed for logs. The MOVE clause only relocates the file; it does not accept growth or filegroup options.

Common Mistakes

  • Putting a log file in a filegroup. Log files are never part of a filegroup. If your script includes FILEGROUP = 'PRIMARY' on the log definition, remove it.
  • Copying a data file template. Scripts generated for data files often include MAXSIZE or FILEGROWTH in ways that are invalid for logs. Trim the log section to the supported options.
  • Assuming the error means the database is corrupt. Error 1041 is a syntax/option error, not a corruption error. The database is fine; the statement is wrong.
  • Ignoring the exact option name. The message tells you which option failed. Fix that one first, then re-run; you may uncover a second invalid option.
  • Editing system databases. Do not attempt to alter the log files of master, model, msdb, or tempdb manually. Those are managed by SQL Server and changes can break the instance.

Tips

  • Keep log file definitions simple: name, physical file path, initial size, and growth increment. That covers most needs and avoids error 1041.
  • Use ALTER DATABASE ... MODIFY FILE for one change at a time. It is easier to isolate which option is rejected.
  • Generate scripts from SSMS (right-click database > Tasks > Generate Scripts) to see the syntax SQL Server itself considers valid for your version.
  • If you are scripting a restore to a new server, use RESTORE FILELISTONLY first to get the logical file names, then build the MOVE clauses without extra options.
  • Test scripts on a development instance before running them against production, especially when changing file sizes or paths.

Troubleshooting

If the error persists after removing the obvious option, check the following. First, confirm you are editing the correct statement: a batch may contain multiple ALTER DATABASE commands, and the failing one may be later in the script. Second, verify the SQL Server version, because the set of allowed file options can vary slightly between versions; use the version's documentation for the exact syntax. Third, if the error occurs during a restore, examine the RESTORE statement for any WITH options that apply to files, and remove those that are not valid for logs. Fourth, if you are using a third-party tool or generated script, regenerate the script using the tool's current version or the vendor's recommended syntax. Fifth, if you cannot identify the option, run the statement in small pieces: create the database with only the data file, then add the log file with a separate ALTER DATABASE statement. Finally, check the SQL Server error log and the Windows Application log for additional context, and ensure you are not accidentally applying a data-file option to a log file through a variable or dynamic SQL string.

Frequently Asked Questions

What does error 1041 mean exactly?

It means an option in your statement is not valid for a transaction log file. SQL Server rejects options that only apply to data files, such as filegroup membership or certain size settings.

Can I set a maximum size on a log file?

In many SQL Server versions, MAXSIZE is allowed on log files, but some contexts or versions reject it. If you get error 1041, remove MAXSIZE from the log definition and set it separately with ALTER DATABASE ... MODIFY FILE if needed.

Why does my CREATE DATABASE script fail only on the log part?

Because the log section likely contains an option copied from the data file section, such as FILEGROUP. Log files do not belong to filegroups.

Does this error affect database integrity?

No. It is a statement error, not a corruption or consistency error. The database remains intact; only the command failed.

Can I fix it by restoring from backup?

No, a restore will not fix a syntax error. You need to correct the statement that is being executed.

Is error 1041 the same on all SQL Server versions?

The error number and meaning are consistent, but the exact set of allowed log file options can differ slightly by version. Always check the documentation for your version.