SQL Server Error 1105—*"Could not allocate space for object"*—occurs when a database table or index exceeds its allocated storage limit, forcing SQL Server to attempt to expand it beyond available space. This typically happens when there’s insufficient free space in the data file or log file, often due to fragmented space, old log files, or insufficient disk capacity. The fix is usually straightforward: reclaim unused space, expand files if needed, or optimize existing storage. Without these steps, tables may grow indefinitely until the database crashes or locks up. Here’s how to resolve it quickly and permanently.

What You'll Need

  • A working SQL Server instance (local or remote) with administrative access
  • SQL Server Management Studio (SSMS), Query Analyzer, or a compatible tool
  • Admin rights to modify database files and disk permissions
  • Knowledge of your database’s file locations (typically in *%ProgramFiles%\Microsoft SQL Server* or *C:\Program Files\Microsoft SQL Server*)

Step-by-Step Solution

  1. Check current disk space usage: Open Command Prompt and run: wmic logicaldisk where "drivatype=3" get size,freespace,caption Look for your SQL Server data/log files (often named *MSSQLDATA.mdf* or *MSSQLLOG.ldf*) in the output. Note the drive where these reside. If free space is critically low (<5% used), proceed to expand files. Otherwise, skip to optimization steps.
  2. Use SQL Server Management Studio to query space usage: Connect to your SQL Server instance via SSMS. Navigate to Object Explorer > Databases > Your_Database > Tables. Right-click a table, select Task > Properties. Under File Options, check the Primary File (MDF) and Secondary File (LDF) sizes.

    In the File tab, verify the physical file paths match what you confirmed in Step 1. If they don’t, the files may be misplaced. On Windows, the default paths are:

    • Primary file (MDF): *C:\Program Files\Microsoft SQL Server\MSSQLXX.MSSQLSERVER\MSSQL\DATA\YourDB.mdf*
    • Log file (LDF): *C:\Program Files\Microsoft SQL Server\MSSQLXX.MSSQLSERVER\MSSQL\DATA\YourDB_log.ldf*
  3. Expand data or log files if needed: If free space is insufficient (<5% remaining), you must manually resize the files.
    1. Stop the SQL Server service via Services.msc or this command: net stop MSSQLSERVER (Replace *MSSQLSERVER* with your instance name if different.)
    2. Locate the files (see Step 2) and right-click each to Shrink File in File Explorer. SQL Server won’t let you shrink below a certain size—this is a temporary step to prepare for resizing.
    3. Rename the files to include the new size (e.g., *YourDB_10GB.mdf*) and restart SQL Server.
    4. In SSMS, right-click the database and select Task > Resize Database. Enter the new target file size or let SQL Server auto-grow it.

    For LDF files, use: ALTER DATABASE YourDB SET FILEGROUP = YourFileGroup (Replace *YourFileGroup* with the group containing the log file.)

  4. Clean up unused space: If files have unused space, reclaim it:
    1. Open a query window in SSMS and run: DBCC SHRINKFILE (DatabaseName, FilenameNumber, targetsize) Replace *DatabaseName* with your DB, *FilenameNumber* with 1 (primary) or 2 (log), and *targetsize* with the free space (e.g., 100MB).
    2. For example, to reclaim 100MB of space on the primary file: DBCC SHRINKFILE (YourDB, 1, 100)
    3. Alternatively, use: DBCC SHRINKFILE (YourDB, 2, 0) (0 means "shrink to current size," which is safer but may fail if the file is fragmented.)

    Note: Shrinking files permanently removes data—verify backups exist before running this.

  5. Optimize indexes and partitions: If the issue persists, fragmented indexes or partitions waste space. Run: ALTER INDEX ALL ON YourTable REORGANIZE To fix just that table. For a database-wide cleanup: DBCC SHOWCONTIG (YourDB, 0) (The output shows fragmentation levels and suggests fixes.)
  6. Move files to a larger, dedicated drive: If SQL Server runs on a small partition (e.g., C:), move the database to a drive with >50% free space:
    1. Stop SQL Server and copy the files to the new location (e.g., *D:\MSSQL\DATA*).
    2. In SQL Server Configuration Manager, edit the *SQL Server Network Configuration* > Protocols for *MSSQLSERVER* to include the new file paths.
    3. Start SQL Server and verify the new location is used in SSMS.

    This is the most future-proof solution.

Common Mistakes

  • Skipping backups: Shrinking files or expanding them without a backup risks data loss. Always take a full backup before modifying files.
  • Ignoring fragmentation: Repeatedly shrinking files without reorganizing indexes or partitions leads to fragmentation, worsening performance.
  • Running DBCC SHRINKFILE on critical tables: Shrinking primary data files (*targetsize=0*) can cause corruption. Use the free space target instead.
  • Incorrect file paths: Double-check file locations after resizing—errors here cause further failures.

Tips

  • Prevent future issues: Set up automatic backup retention policies and monitor disk space via Event Viewer (look for "Log space exceeded" events).
  • Use auto-growth for development: In SSMS, enable Auto-Grow File on the database properties tab to avoid manual resizing.
  • Monitor log file size: If the log file (*.ldf*) grows uncontrollably, consider archiving old logs or adjusting retention settings.
  • Avoid DELETE operations on large tables: Frequent large DELETEs can fragment data—use MERGE or bulk inserts instead.

Troubleshooting

If the error persists after basic steps:

  1. Check for file locks: Run this query to see if any processes are holding locks on the files: SELECT * FROM sys.dm_tran_locks WHERE resource_database_id = DB_ID('YourDB') AND resource_associated_entity_id IN (0, 1) If locks persist, wait or contact the application owner to release them.
  2. Verify disk I/O performance: Open Resource Monitor (Windows Task Manager > Performance tab > Open Resource Monitor) and check for disk bottlenecks. If the disk is maxed out, upgrade storage.
  3. Reinstall SQL Server if corrupted: If files are corrupted after shrinking, restore from backup. As a last resort, reinstall SQL Server (backup critical data first).
  4. Test with a new database: Create a new database in the same file structure and check if the issue occurs. If not, the original DB may have corrupted permissions or metadata.

Frequently Asked Questions

Why does SQL Server need to allocate space for objects?

SQL Server dynamically expands tables and indexes when space runs low. When it fails, it typically means the allocated file is full, or the database is fragmented. Expanding files or cleaning up space resolves it.

Can I shrink files in SQL Server 2019+?

Yes, but with caution. Modern versions of SQL Server support DBCC SHRINKFILE with safety checks. Always back up before shrinking.

What happens if I shrink a table without free space?

The operation will fail with an error like "Insufficient space" or "File too small." You must first expand files or reclaim unused space.

How often should I shrink files?

Only when needed (e.g., free space <5%). Frequent shrinking causes fragmentation. Use DBCC SHOWCONTIG to check before shrinking.

My database won't start after a shrink—what’s wrong?

This usually means files are corrupted or permissions are misconfigured. Restore from backup and verify file paths in SSMS.

Can I automate this process?

Yes! Use agents in SQL Server to run DBCC SHRINKFILE at set intervals. For production, pair this with monitoring tools like SQL Agent jobs.