Coding⏱️ 2 min read📅 2026-05-31

How to Fix: How to set command timeout in ASP.NET Core / Entity Framework Core?

Adjust the Entity Framework Core command timeout to handle large file uploads.

Quick Answer: Set the `Command Timeout` property in the `DbContextOptionsBuilder` configuration.

In ASP.NET Core / Entity Framework Core, the command timeout is no longer set in the same place as earlier versions. However, you can still increase the command timeout by setting the CommandTimeout property on the DbContext or using the UseTransaction method.

🛑 Root Causes of the Error

  • The default command timeout is 30 seconds, which may not be sufficient for large file uploads.

🔧 Proven Troubleshooting Steps

Method 1: Increase Command Timeout on DbContext

  1. Step 1: Open your DbContext and set the CommandTimeout property to a higher value, such as 60 or 90 seconds.

Method 2: Use Transaction with Increased Command Timeout

  1. Step 1: Wrap your database operations in a using (var transaction = DbContext.Database.BeginTransaction()) block.

💡 Conclusion

By following these steps, you can increase the command timeout and prevent timeouts during large file uploads.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions