Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 大型json字符串的SQL Azure连接已关闭_C#_Sql Server_Azure_Azure Sql Database_Dapper - Fatal编程技术网

C# 大型json字符串的SQL Azure连接已关闭

C# 大型json字符串的SQL Azure连接已关闭,c#,sql-server,azure,azure-sql-database,dapper,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 avail

我试图将一个较大的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();
        }
    }
public async Task SaveNewAsync(PublisherDto publisher,int userID)
{
使用(var cnn=new SqlConnection(ConfigurationManager.ConnectionStrings[“DefaultConnection”].ToString())
{
var b=等待cnn.QueryAsync(“s_PublisherInsert”,新
{
publisher.cv_id,
publisher.Name,
publisher.ThumbImageUrl,
publisher.FullImageUrl,
用户ID,
publisher.cv_网址,
publisher.JsonData,
publisher.cv\u版本\u哈希
},commandType:commandType.StoredProcess,commandTimeout:60);
返回b.FirstOrDefault();
}
}

有没有人遇到过同样的问题,并且知道如何解决它?

您已经设置了命令超时,但没有提到连接到数据库时的超时。我建议在连接字符串中扩展连接超时。

您已经设置了命令超时,但不要提及连接到数据库时的超时。我建议延长连接字符串中的连接超时时间。

我遇到了这个问题,无法准确诊断问题的根源,但我引入了连接弹性类,以便在出现故障时自动重试。同样,虽然这不能解决或识别潜在的根本问题,但它确实使应用程序对该问题具有健壮性

我使用实体框架连接到Azure SQL,使用DbExecutionStrategy实现弹性连接的基本方法是


看起来您可能正在使用ADO进行连接。下面是一篇关于实现的有用文章。

我遇到了这个问题,无法准确诊断问题的根源,但我引入了一个连接弹性类来自动重试失败。同样,虽然这不能解决或识别潜在的根本问题,但它确实使应用程序对该问题具有健壮性

我使用实体框架连接到Azure SQL,使用DbExecutionStrategy实现弹性连接的基本方法是


看起来您可能正在使用ADO进行连接。下面是一篇关于实现的有用文章。

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

希望能有帮助


-RN

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

希望能有帮助


-RN

设置为30秒,但错误会立即发生,而不是30秒后。将其增加到360度左右,然后尝试一下。您的连接似乎由于某种原因被切断。设置为30秒,但错误会立即发生,而不是在30秒后发生。请将其增加到360度,然后再试一次。您的连接似乎因某种原因被切断。在依赖网络时,这始终是一种良好的做法。(有时候事情就是失败了;如果没有,其他人会透明地为你处理错误。)这在依赖网络时总是一个好的做法。(有时事情只是失败了;如果没有,其他人会透明地为您处理错误。)“使用0值等待,而不会引发异常。”这为我解决了这个问题,非常感谢。将超时设置为0将进一步推动问题的解决。最终,您的应用程序编写这些JSON对象的速度将降低到可接受的限制以下。如果您需要编写大量大型JSON对象,DocumentDB是比Windows azure SQL数据库更好的azure解决方案。“使用0值等待,而不会引发异常。”这为我修复了它,非常感谢。将超时设置为0将使问题进一步恶化。最终,您的应用程序编写这些JSON对象的速度将降低到可接受的限制以下。如果您需要编写大量大型JSON对象,DocumentDB是比WindowsAzure SQL数据库更好的azure解决方案。