Kestrel .NET API - 无法连接 mongodb// url
Kestrel .NET API - Cannot connect with mongodb// url
我已经配置了连接到 Mongo 数据库的 .net 核心 API。我已经从 ConnectionString 连接到它,如 "mongodb//user:password@server ..."。目前,在本地连接很好,我可以连接 MongoDB。问题是当我发布它时,服务器日志流向我显示了与 Kestrel 代理相关的内容,并且无法解析 "mongodb://"。事实上,mongodb 字符串看起来像 unknown。
我已经在 app.settings.json 文件中配置了连接:
"ConnectionStrings":{
"db": "mongodb://admin:blbablabla@url:27017/?authSource=admin"
var uri = new MongoUr(_configuration.GetSection(CONNECTIONSTRINGS)[db];
_mongoDBClient = new MongoClient(uri);
那就是错误:
2019-01-25 13:10:42.366 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HLK2OOVSKRD5", Request id "0HLK2OOVSKRD5:00000001": An unhandled exception was thrown by the application.
System.TimeoutException: A timeout occured after 30000ms selecting a
server using CompositeServerSelector{ Selectors =
MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector,
LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }.
Client view of cluster state is { ClusterId : "1", ConnectionMode : "
Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId:
"{ ClusterId : 1, EndPoint : "Unspecified/urlmachine:27017" }", EndPoint:
"Unspecified/urlmachine:27017", State: "Disconnected", Type: "Unknown",
HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception
occurred while opening a connection to the server. --->
System.Net.Sockets.SocketException: No such host is known
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
at System.Net.Dns.<>c.<GetHostAddressesAsync>b__25_1(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
我已经解决了问题。该错误是因为该应用无法连接到 MongoDB。 MongoDB 数据库位于无法访问的网络中
我已经配置了连接到 Mongo 数据库的 .net 核心 API。我已经从 ConnectionString 连接到它,如 "mongodb//user:password@server ..."。目前,在本地连接很好,我可以连接 MongoDB。问题是当我发布它时,服务器日志流向我显示了与 Kestrel 代理相关的内容,并且无法解析 "mongodb://"。事实上,mongodb 字符串看起来像 unknown。
我已经在 app.settings.json 文件中配置了连接:
"ConnectionStrings":{ "db": "mongodb://admin:blbablabla@url:27017/?authSource=admin"
var uri = new MongoUr(_configuration.GetSection(CONNECTIONSTRINGS)[db];
_mongoDBClient = new MongoClient(uri);
那就是错误:
2019-01-25 13:10:42.366 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HLK2OOVSKRD5", Request id "0HLK2OOVSKRD5:00000001": An unhandled exception was thrown by the application.
System.TimeoutException: A timeout occured after 30000ms selecting a
server using CompositeServerSelector{ Selectors =
MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector,
LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }.
Client view of cluster state is { ClusterId : "1", ConnectionMode : "
Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId:
"{ ClusterId : 1, EndPoint : "Unspecified/urlmachine:27017" }", EndPoint:
"Unspecified/urlmachine:27017", State: "Disconnected", Type: "Unknown",
HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception
occurred while opening a connection to the server. --->
System.Net.Sockets.SocketException: No such host is known
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
at System.Net.Dns.<>c.<GetHostAddressesAsync>b__25_1(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
我已经解决了问题。该错误是因为该应用无法连接到 MongoDB。 MongoDB 数据库位于无法访问的网络中