What is “Connect Timeout” in sql server connection string?

后端 未结 8 1732
半阙折子戏
半阙折子戏 2020-12-06 08:46

I have the following connection string(get from a property of sql server):

Data Source=(LocalDB)\\v11.0;AttachDbFilename=C:\\Users\\myUser\\Desktop\\adoBanch         


        
8条回答
  •  时光说笑
    2020-12-06 09:35

    Connection Timeout=30 means that the database server has 30 seconds to establish a connection.

    Connection Timeout specifies the time limit (in seconds), within which the connection to the specified server must be made, otherwise an exception is thrown i.e. It specifies how long you will allow your program to be held up while it establishes a database connection.

    DataSource=server;
    InitialCatalog=database;
    UserId=username;
    Password=password;
    Connection Timeout=30
    

    SqlConnection.ConnectionTimeout. specifies how many seconds the SQL Server service has to respond to a connection attempt. This is always set as part of the connection string.

    Notes:

    • The value is expressed in seconds, not milliseconds.

    • The default value is 30 seconds.

    • A value of 0 means to wait indefinitely and never time out.

    In addition, SqlCommand.CommandTimeout specifies the timeout value of a specific query running on SQL Server, however this is set via the SqlConnection object/setting (depending on your programming language), and not in the connection string i.e. It specifies how long you will allow your program to be held up while the command is run.

提交回复
热议问题