How to extend the timeout of a SQL query

前端 未结 6 1846
没有蜡笔的小新
没有蜡笔的小新 2021-02-11 14:21

This is not a connection timeout as a connection to the database is made fine. The problem is that the stored procedure that I\'m calling takes longer than, say, 30 seconds and

6条回答
  •  长情又很酷
    2021-02-11 14:45

    Try this one

    SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(connection.ConnectionString);
    connectionStringBuilder.ConnectTimeout = 180;
    connection.ConnectionString = connectionStringBuilder.ConnectionString;
    
    connection.Open();
    SqlCommand command = new SqlCommand("sp_ProcedureName", connection);
    command.CommandType = CommandType.StoredProcedure;
    command.CommandTimeout = connection.ConnectionTimeout;
    command.ExecuteNonQuery();
    connection.Close();
    

提交回复
热议问题