我有一个使用dotnet core 3.1和EF core 3.1开发的Web API。我在IBM云中创建了一个postgreSQL Db,可以使用PgAdmin访问它。但是,当我尝试通过代码连接到数据库时,出现以下错误。
[System.Net.Sockets.SocketException: Can't assign requested address
at at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
at at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
at at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0``1.<<StartAsync>g__OnBind|0>d.MoveNext()
at at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
at at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)
at at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func
2 createBinding)在Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync [TContext](IHttpApplication 1 application, CancellationToken cancellationToken)
at at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Marketplace.Api.Program.Main(String[] args) in /Users/jayasuryajeyakodi/my/startup/Marketplace/Marketplace.BackEnd/Marketplace.Api/Program.cs:16
这是我在startup.cs中的编码方式
connectionString = "Server=*.databases.appdomain.cloud;Database=*;Port=30331;User Id=ibm_cloud_*;Password=*;
您的错误似乎与Npgsql或数据库连接无关。如果检查堆栈跟踪,可以看到Npgsql不在其中,并且在Kestrel尝试设置套接字传输时,会从Socket.Bind中引发异常。您可能已指定了要绑定/监听的地址,并且该地址无效。这可能是网络配置问题。