I want the database connection to my SQL Server to be fast. How to reduce the timeout? I tried adding Connection Timeout=1to the connection string, but that doesn't seem to matter.
With Connection Timeout=500, it takes about 8 minutes 30 seconds to timeout. It is expected. Using Connection Timeout=1the timeout takes about 40 seconds, which is much longer than expected.
I found the property EntityConnection.ConnectionTimeout, but it is read-only. Is there anything else I can do to reduce this timeout? Is this a problem with Entity?
UPDATE: Here is my connection string. ~ 40 seconds are still required before a timeout.
<add name="KofaxAdminToolsEntities" connectionString="metadata=res://*/DB.Model.KofaxAdminTools.csdl|res://*/DB.Model.KofaxAdminTools.ssdl|res://*/DB.Model.KofaxAdminTools.msl;provider=System.Data.SqlClient;provider connection string="data source=MY_DATASOURCE;initial catalog=MY_CATALOG;persist security info=True;user id=MY_USER;password=MY_PASSWORD;MultipleActiveResultSets=True;App=EntityFramework;Connection Timeout=1"" providerName="System.Data.EntityClient" />
UPDATE 2: . Thus, I found that the timeout was tcp timeout , not sql connect timeout . If my machine could reach the host, @marc_s's solution would work, however, since I cannot reach this host, tcp timeout comes into play. Does anyone know how to reduce tcp timeout for SqlConnection?
source
share