sqlsugar配置连接时间设置
时间: 2023-09-19 12:11:07 浏览: 707
在 SqlSugar 的配置中,可以通过以下方式设置连接超时时间:
1. 使用 `AdoNetProvider` 配置连接字符串,设置 `ConnectTimeout` 属性:
```csharp
// 以 SQL Server 为例
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "Data Source=.;Initial Catalog=TestDb;Integrated Security=True;Connect Timeout=30",
DbType = DbType.SqlServer,
InitKeyType = InitKeyType.Attribute
});
```
2. 使用 `ConnectionString` 配置连接字符串,设置 `Connect Timeout` 属性:
```csharp
// 以 MySQL 为例
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server=localhost;database=test;uid=root;pwd=123456;Connect Timeout=30",
DbType = DbType.MySql,
InitKeyType = InitKeyType.Attribute
});
```
在上述示例中,将连接超时时间设置为了 30 秒。可以根据实际情况进行调整。
阅读全文
相关推荐


















