I want to automatically create the database and table structures when my desktop app is first run.
I can't find any examples or documentation on something equivalent for EFCore.
I did everything as it is in this documentation:
https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core-example.html
But I still have a problem: Exception thrown: 'Microsoft.Data.SqlClient.SqlException' in Microsoft.Data.SqlClient.dll, and empty database :( Please help me, if you can.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
try
{
optionsBuilder.UseMySQL("server=localhost;userid=root;password=topSecret;database=kartoteka-pracownicza");
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to server. Contact administrator");
break;
case 1045:
MessageBox.Show("Invalid username/password, please try again");
break;
}
};
}