-
-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change WithDatabase method to public #984
Change WithDatabase method to public #984
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the Microsoft SQL Server Docker image does not support the configuration of the database or username through environment variables during the container start. Changing the modifier to public
will not create or configure the database. This limitation is from the image itself, rather than a constraint from Testcontainers.
testcontainers-dotnet/src/Testcontainers.MsSql/MsSqlBuilder.cs
Lines 102 to 104 in b121dde
/// <remarks> | |
/// The Docker image does not allow to configure the database. | |
/// </remarks> |
Nevertheless, the image does allow the execution of customized SQL scripts (with a couple of adjustments). Along with WithResourceMapping(bytes[], string)
, we can utilize this to configure the database or username. Furthermore, this enhances the capabilities of the module (image) to similar functionalities like PostgreSQL image offers.
Another alternative is to use the EF or override the database in the connection string.
This issue relates:
What @MarkusKeusch and me want is just to have the "initialCatalog" of the connection string set to a specific DB. Of course we can set the initalCatalog in our project manually or make our own extension method. We will care ourself about creating the DB. But it would be nice to have the functionality directly from testcontainers. I understand that @HofmeisterAn What do you think about adding an overload for GetConnectionString(), where you can specify the DB, like this: Or what if we make a builder method |
You are referring to the workaround mentioned above, in which Entity Framework creates the database if it does not already exist, right? As previously mentioned, I believe this can be quite misleading. If developers do not utilize EF to generate the non-existent database, they run into issues. I will close this issue. Let's continue the discussion in #986 and see if we can find a suitable solution. |
What does this PR do?
Expose the
WithDatabase
method ofMsSqlBuilder
Why is it important?
By default the initial catalog of the connectionstring is set to master. In some cases we want to just delete and recreate the whole database which is not possible for the master database.
Related issues