Changing SqlConnection timeout

后端 未结 10 2122
孤街浪徒
孤街浪徒 2020-12-25 09:22

I am trying to override the default SqlConnection timeout of 15 seconds and am getting an error saying that the

property or indexer cann

10条回答
  •  攒了一身酷
    2020-12-25 09:55

    You can also use the SqlConnectionStringBuilder

    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(ConnectionString);
    builder.ConnectTimeout = 10;
    using (var connection = new SqlConnection(builder.ToString()))
    {
        // code goes here
    }
    

提交回复
热议问题