c# - SQL Azure 连接因大型 json 字符串而关闭

标签 c# sql-server azure azure-sql-database dapper

我尝试将较大的 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();
        }
    }

有人遇到过同样的问题并且有解决办法吗?

最佳答案

尝试将超时设置为更高的值。根据文档,错误与超时有关。

https://support.microsoft.com/en-us/kb/555938

希望有帮助。

-RN

关于c# - SQL Azure 连接因大型 json 字符串而关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39056732/

相关文章:

postgresql - azure + postgresql : How to fix error: Unable to connect to server: server closed the connection unexpectedly

azure - 如何使用流量管理器后面的多个应用服务与自定义域设置 SSL?

c# - 如何在按钮单击时聚焦文本框

c# - C#中的变量对象

sql-server - SQL Server Management Studio 修改存储过程时用双引号替换单引号

sql - 将 nvarchar 转换为日期时间

c# - 如何在 WPF 中设置元素的样式属性

c# - ASP.NET 用 html 数字替换双引号

sql - 仅在三个表中连接一行

azure - 使用 Azure 平台的 ARR 反向代理