How to fix the timeout expired in and MS sql server?

If your query needs more than the default 30 seconds,

Set the Timeout in connectionstring like Timeout="400000";


  • use the below code for ADO.NET connection:

1.     declare "Connect Timeout" in the connection string
        Database=WIMS;Server=(local);User Id =(Username); Password=(password);Connect                              Timeout=3000000"

2.     SqlCommand.CommandTimeout
        using (var connection = new SqlConnection(connectionString))

         SqlCommand command = new SqlCommand("SpGetEmployee", connection);
         command.CommandType = CommandType.StoredProcedure;

         // Setting command timeout to 3000000 second

         command.CommandTimeout = 3000000;

  • In entity framework you can use the below code:
<add name="TestEntities" connectionString="metadata=res://*/DbManager.Model1.csdl|res://*/DbManager.Model1.ssdl|res://*/DbManager.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=Test;user id=sa;password=12345;MultipleActiveResultSets=True;Timeout=4000000;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />


Post a Comment


  1. While finding examples out of information, AI attempts to search for certain examples or quest for certain information relationship in a circumstance where labeled information is missing. ExcelR Data Science Courses

  2. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    On Demand Service Apps For Android and iOS are highly in demand as through this online platform. App ideas provide them on-demand service when customers need it.