Hello Oscar Chavarria,
Thank you for posting your question in the Microsoft Q&A forum.
The connection issues between your .NET 9 application and Azure Cosmos DB for MongoDB (vCore) likely stem from DNS resolution or driver-specific handling of the connection string, despite working in Python with PyMongo. The timeout error suggests the MongoDB .NET driver fails to discover cluster nodes, possibly due to:
- DNS Propagation Delays: The mongodb+srv protocol relies on SRV records, which may not resolve consistently across environments.
- Driver Configuration: The .NET driver might interpret timeout settings differently—try explicitly increasing connectTimeoutMS and serverSelectionTimeoutMS in the connection string.
- TLS/SSL Handshake: Ensure the system running .NET trusts Azure’s TLS certificates (unlike Python, which may bypass stricter checks).
- Connection String Format: While escaping special characters helps, verify the full URI adheres to Azure’s vCore requirements (e.g., retrywrites=false is critical).
For troubleshooting:
- Replace mongodb+srv with a standard connection string (list explicit host/port) to bypass SRV issues.
- Test with MongoDB.Driver 2.19+ (some users report better compatibility).
- Capture network traces (dotnet-trace or Wireshark) to confirm DNS/TLS failures.
- If using Azure Private Link, validate DNS resolution aligns with private endpoints.
Since Compass also fails, this points to a platform/network-level inconsistency rather than code. Engage Azure Support with correlation IDs and network traces for deeper diagnosis.
If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue. Your contribution to the Microsoft Q&A community is highly appreciated.