SqlConnectionStringBuilder.ConnectTimeout Property
.NET Framework 4
Gets or sets the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.
Assembly: System.Data (in System.Data.dll)
The following example first displays the contents of a connection string that does not specify the "Connect Timeout" value, sets the ConnectTimeout property, and then displays the new connection string.
using System.Data.SqlClient; class Program { static void Main() { try { string connectString = "Server=(local);Initial Catalog=AdventureWorks;" + "Integrated Security=true"; SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); Console.WriteLine("Original: " + builder.ConnectionString); Console.WriteLine("ConnectTimeout={0}", builder.ConnectTimeout); builder.ConnectTimeout = 100; Console.WriteLine("Modified: " + builder.ConnectionString); Console.WriteLine("Press any key to finish."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.