You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modify SqlServerTestDatabase to Handle Database Creation:
public void InitializeDatabase()
{
// Open the connection to the server (without specifying a database)
Connection.Open();
//Check if the database exists
var cmd = new SqlCommand("IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'Testing') BEGIN CREATE DATABASE Testing END", Connection);
cmd.ExecuteNonQuery();
// Close the connection and reopen with the correct database
Connection.Close();
Connection.ChangeDatabase("Testing");
// Initialize the database context to apply migrations or creation logic
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServer(Connection)
.Options;
using var context = new AppDbContext(options, null!);
context.Database.EnsureCreated();
}
Hey,
First of all amazing template, I build a financial app with ease.
Now I'm getting around to writing my tests 😞.
I see you used Sqlite for you test db in your integration tests.
I would like to use an SqlServer test db but can't seem to get it to work.
Error: Microsoft.Data.SqlClient.SqlException : Cannot open database "Testing" requested by the login. The login failed.
Tried:
The code based on your template is below.
Hopefully one you guys can help me further 😃.
Thanks in advance,
Nathan
The text was updated successfully, but these errors were encountered: