SQL Azure 连接因 json 大字符串而关闭
SQL Azure connection closed for large json strings
我正在尝试将较大的 json 字符串 (c.2Mb) 保存到 SQL Azure 数据库中的 NVARCHAR(MAX) 列,但出现以下异常:
[SqlException (0x80131904): A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)]
如果我将 json 字符串设置为“”,则 INSERT 语句工作正常。我已经用相同的方法成功保存了其他更小的 json 字符串。立即抛出异常,因此感觉不像是超时。尽管如此,我已经尝试更改连接和命令超时,但无济于事。
我正在使用 Dapper 与 SQL:
交谈
public async Task<PublisherDto> SaveNewAsync(PublisherDto publisher, int userID)
{
using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
{
var b = await cnn.QueryAsync<PublisherDto>("s_PublisherInsert", new
{
publisher.cv_id,
publisher.Name,
publisher.ThumbImageUrl,
publisher.FullImageUrl,
userID,
publisher.cv_Url,
publisher.JsonData,
publisher.cv_version_hash
}, commandType: CommandType.StoredProcedure, commandTimeout: 60);
return b.FirstOrDefault();
}
}
有没有人遇到过同样的问题并且知道如何解决它?
你已经设置了命令超时,但没有提到什么是连接到数据库的超时。我建议延长连接字符串中的连接超时。
我遇到了这个问题,无法准确诊断问题的根源,但我引入了连接弹性 class 以在出现故障时自动重试。同样,虽然这不能解决或确定潜在的根本问题,但它确实使应用程序对问题具有鲁棒性。
我使用 Entity Framework 连接到 Azure SQL,有关使用 DbExecutionStrategy 实现弹性连接的基本方法是 here。
看起来您可能正在使用 ADO 进行连接。这是关于实施 ADO.NET Connection Resiliency.
的有用 post
尝试将超时设置得更高一些。根据文档,错误与超时有关。
https://support.microsoft.com/en-us/kb/555938
希望对您有所帮助。
-RN
我正在尝试将较大的 json 字符串 (c.2Mb) 保存到 SQL Azure 数据库中的 NVARCHAR(MAX) 列,但出现以下异常:
[SqlException (0x80131904): A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)]
如果我将 json 字符串设置为“”,则 INSERT 语句工作正常。我已经用相同的方法成功保存了其他更小的 json 字符串。立即抛出异常,因此感觉不像是超时。尽管如此,我已经尝试更改连接和命令超时,但无济于事。
我正在使用 Dapper 与 SQL:
交谈 public async Task<PublisherDto> SaveNewAsync(PublisherDto publisher, int userID)
{
using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
{
var b = await cnn.QueryAsync<PublisherDto>("s_PublisherInsert", new
{
publisher.cv_id,
publisher.Name,
publisher.ThumbImageUrl,
publisher.FullImageUrl,
userID,
publisher.cv_Url,
publisher.JsonData,
publisher.cv_version_hash
}, commandType: CommandType.StoredProcedure, commandTimeout: 60);
return b.FirstOrDefault();
}
}
有没有人遇到过同样的问题并且知道如何解决它?
你已经设置了命令超时,但没有提到什么是连接到数据库的超时。我建议延长连接字符串中的连接超时。
我遇到了这个问题,无法准确诊断问题的根源,但我引入了连接弹性 class 以在出现故障时自动重试。同样,虽然这不能解决或确定潜在的根本问题,但它确实使应用程序对问题具有鲁棒性。
我使用 Entity Framework 连接到 Azure SQL,有关使用 DbExecutionStrategy 实现弹性连接的基本方法是 here。
看起来您可能正在使用 ADO 进行连接。这是关于实施 ADO.NET Connection Resiliency.
的有用 post尝试将超时设置得更高一些。根据文档,错误与超时有关。
https://support.microsoft.com/en-us/kb/555938
希望对您有所帮助。
-RN