Connection timeout for SQL server

后端 未结 3 1229
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 03:44

Can I increase the timeout by modifying the connection string in the web.config?

3条回答
  •  伪装坚强ぢ
    2020-11-28 04:18

    If you want to dynamically change it, I prefer using SqlConnectionStringBuilder .

    It allows you to convert ConnectionString i.e. a string into class Object, All the connection string properties will become its Member.

    In this case the real advantage would be that you don't have to worry about If the ConnectionTimeout string part is already exists in the connection string or not?

    Also as it creates an Object and its always good to assign value in object rather than manipulating string.

    Here is the code sample:

    var sscsb = new SqlConnectionStringBuilder(_dbFactory.Database.ConnectionString);
    
    sscsb.ConnectTimeout = 30;
    
    var conn = new SqlConnection(sscsb.ConnectionString);
    

提交回复
热议问题