Testcontainers CosmosDB / WebApplication Factory ConnectionString Not Working
anyone familiar with WebApplicationFactory / Testcontainers?
The below is giving me
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
someone mentioned ports earlier?14 Replies
I've used it a bit, but without knowing which line threw the exception in particular, I would caution that when using the web application factory will call the entry point in your
Program
class. If you have any startup code there, you may need to override any and all initialization you're doing within the builder.ConfigureServices(_ => { })
method.
Alternatively, it could be the connection string formatting from similar exception messagesUnknown User•7mo ago
Message Not Public
Sign In & Join Server To View
I have changed it to this, which is still not working (and containers are not disposing properly either):
You sure its not the connectionstring thats poorly formatted?
Mapped public port for Cosmos DB: 56685
Connection string generated: AccountEndpoint=https://127.0.0.1:56685/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
https://www.connectionstrings.com/sql-server/
I'm no connectionstring expert but try take a look at this. What dbserver are you using?
SQL Server connection strings - ConnectionStrings.com
Connection strings for SQL Server. Connect using Microsoft.Data.SqlClient, SqlConnection, MSOLEDBSQL, SQLNCLI11 OLEDB, SQLNCLI10 OLEDB, SQLNCLI OLEDB.
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
sorry, my brain is mushy today
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-dotnet-get-started?tabs=azure-cli%2Cwindows
If it doesn't work the DI way. Try creating an azurecredential and see if you can make a dbclient that way
Get started with Azure Cosmos DB for NoSQL using .NET
Get started developing a .NET application that works with Azure Cosmos DB for NoSQL. This article helps you learn how to set up a project and configure access to an Azure Cosmos DB for NoSQL endpoint.
sorry I am confused how that relates here, here is my Program.cs setup for CosmosDB:
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
bump still no success 😦
Ok so the weird thing is, this seems to be an issue with how I am instantiating my cosmos client
Not to do with Testcontainers itself
The exception is actually being thrown here in my Program.cs:
Yeah definitely a bum connection string. usually you wouldn't have the IP address like that, it's probably expecting
localhost
instead (I'll admit I may be a dummy but just a guess), CosmosClient when instantiated will look to make a real connection outwards
otherwise you would need to make an actual connection to a hosted cosmos db instance, or are you running the emulator?
try specifying the values through the constructor properties so you can rule whether it's straight up formatting giving you trouble: