Export (0) Print
Expand All

SqlConnectionStringBuilder.ConnectTimeout Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the connection timeout.

Namespace: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)

public int ConnectTimeout { get; set; 
/** @property */
public int get_ConnectTimeout ()

/** @property */
public void set_ConnectTimeout (int value)

public function get ConnectTimeout () : int

public function set ConnectTimeout (value : int)

Property Value

The value of the ConnectTimeout property, or 15 if no value has been supplied.

This property corresponds to the "Connect Timeout", "connection timeout", and "timeout" keys within the connection string.

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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft