- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 C# MVC Web API,它使用 MongoDb 作为后端。我尝试使用
连接到我的 mongodb 数据库MongoClient mongoClient = new MongoClient(connectionString)
其中连接字符串的格式为:mongodb://Username:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95c5f4e6e6e2fae7f1d5fdfae6e1fbf4f8f0bbf0f4e6e1e0e6bbf6f9fae0f1f4e5e5bbf4efe0e7f0bbf6faf8" rel="noreferrer noopener nofollow">[email protected]</a>
Mongo db 托管在 Azure 中的虚拟机中。我能够连接到数据库并且一切正常。但我经常遇到异常:
"MongoDb.driver.MongoConnectionException".An exception occurred while receivinf a message from server--->System.IO.IOException:Unable to read data from the transport connection : A connection attempt failed because the connected party did not properly respond after a period of time,......"
经过一番研究,我了解到 Azure 正在终止空闲连接,我必须设置 MaxConnectionIdleTime
.
为了设置 MaxConnectionIdleTime 我决定通过以下方式连接到 Mongodb
var credential = MongoCredential.CreateCredential("dbname", "UserName", "Password");
var settings = new MongoClientSettings
{
Credentials = new[] { credential },
Server = new MongoServerAddress("HostName", 27017),
MaxConnectionIdleTime = new TimeSpan(0, 3, 0)
};
MongoClient mongoClient = new MongoClient(settings);
在本例中,我使用之前连接的连接字符串中给出的相同用户名和密码组合。
尝试在此处连接时,我遇到了内部异常:
MongoDB.Driver.MongoAuthenticationException: "Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1".
最佳答案
“MongoDb.driver.MongoConnectionException”。从服务器接收消息时发生异常--->System.IO.IOException:无法从传输连接读取数据:连接尝试失败,因为连接方未正确处理一段时间后回复,....
此异常背后的原因是当托管在 Azure 中时,Azure 尝试终止空闲连接,但 C# 驱动程序不知道这一点。驱动程序尝试在已终止的连接上执行查询,但不知道该连接不存在。
对我来说解决方案是在连接字符串中设置 maxIdleTimeMS=45000。
这样驱动程序就不会使用长时间空闲的连接。
这是适合我的连接字符串
connectionString="用户名: [email protected]/?connectTimeoutMS=30000&socketTimeoutMS=30000&waitQueueTimeoutMS=30000&maxIdleTimeMS=45000"
关于mongodb - 无法使用 MongoClientSettings 作为 MongoClient 的参数连接到 MongoDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40436754/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!