Git Product home page Git Product logo

Comments (8)

lauxjpn avatar lauxjpn commented on May 25, 2024

I have just updated to 8.0.1 [...]

@pantonis What version of Pomelo where you using before the upgrade?


ServerVersion.AutoDetect(connectionString) opens a connection to the database server to retrieve the version of the server. If you add a migration and EF Core runs the code that executes ServerVersion.AutoDetect(connectionString), the database server referenced in the connection string must be available, or the ServerVersion cannot get detected:

/// <summary>
/// Retrieves the <see cref="ServerVersion"/> (version number and server type) from a database server.
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <returns>The <see cref="ServerVersion"/>.</returns>
/// <remarks>
/// Uses a connection string to open a connection to the database server and then executes a command.
/// The connection will ignore the database specified in the connection string. It therefore makes not difference, whether the
/// database already exists or not.
/// </remarks>
public static ServerVersion AutoDetect(string connectionString)
{
using var connection = new MySqlConnection(
new MySqlConnectionStringBuilder(connectionString)
{
Database = string.Empty,
AutoEnlist = false,
Pooling = false,
}.ConnectionString);
connection.Open();
return Parse(connection.ServerVersion);
}

To generate the appropriate migrations, Pomelo needs to know the correct server version.

We generally do not recommend using ServerVersion.AutoDetect(connectionString) in production code. We recommend to explicitly specify the ServerVersion (which you now switched to), for example:

var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>()
    .UseMySql(
        connectionString,
        ServerVersion.Parse("10.10.1-mariadb"),
        options =>
        {
            options.EnableRetryOnFailure();
            options.MigrationsAssembly("MyAssembly.MariaDb");
        });

from pomelo.entityframeworkcore.mysql.

pantonis avatar pantonis commented on May 25, 2024

We updated 8.X but we didn't use migrations on 8.0.0. We used migrations on 7.X and then on 8.0.1 where we hit the issue We have several clients each running different version of MariaDb. If we configure it somehow on each client then on each client update of MariaDb we need to update all of it microservices. This is very inconvienent as we have a lot of clients and dozens of microservices that need to be updated. Any other workaround

from pomelo.entityframeworkcore.mysql.

lauxjpn avatar lauxjpn commented on May 25, 2024

Pomelo needs to know the version of the database server (or at least the minimum server version it should support).

If you want to use ServerVersion.AutoDetect(connectionString), the database server that you reference in connectionString must be reachable.

If you are having multiple clients with different database server versions, they are also using different connection strings.
You can configure the connection string in a settings file, along with the server version string.


If you want to use the latest features for all your clients, you should generate an individual migration set for each client using their individual database server version.

If you don't care about the latest MariaDB features for all you clients, you could specify a static minimum server version that is <= the lowest server version of any of your clients. Then you can generate one set of migrations that works for all your clients.

from pomelo.entityframeworkcore.mysql.

pantonis avatar pantonis commented on May 25, 2024

If you want to use ServerVersion.AutoDetect(connectionString), the database server that you reference in connectionString must be reachable.

It is reachable. That is why I opened the ticket. Because with 7.0 version we didn't have any issues on that.

from pomelo.entityframeworkcore.mysql.

lauxjpn avatar lauxjpn commented on May 25, 2024

It is reachable. That is why I opened the ticket. Because with 7.0 version we didn't have any issues on that.

If I understand you correctly, you said earlier that you did not use migrations before 8.0.1:

We updated 8.0 but we didn't use migrations on 8.0.0.

Did I understand you correctly, or did you use migrations before 8.0.1?

from pomelo.entityframeworkcore.mysql.

pantonis avatar pantonis commented on May 25, 2024

Apologies for confusing you. We didn't use it for 8.0.0. We used it for version 7.X and then we upgraded to 8.0.1 and tried to use it on 8.0.1. This is where we noticed the issue. Let me correct my initial message

from pomelo.entityframeworkcore.mysql.

lauxjpn avatar lauxjpn commented on May 25, 2024

Please check, that you can indeed connect to the database from the same machine, that you execute the Add-Migration command on.

Execute the following in a new console program on the same machine, that you execute the Add-Migration command on (use <PackageReference Include="MySqlConnector" Version="2.3.5" />):

var connectionString = "your connection string 100% identical to the one you use in your app";
using var connection = new MySqlConnection(connectionString);
connection.Open();

If it works, then move to the next section below.
If it fails, then you don't have a working connection to the database referenced in your connection string.


There was a single change between 8.0.0 and 8.0.1 in regards to the ServerVersion.AutoDetect() method, that added AutoEnlist = false and Pooling = false to the connection string.

Those changes should not have any influence on the matter, but if you want to verify this, you could revert those changes in a customized auto detect method:

public static ServerVersion CustomAutoDetect(string connectionString) 
{ 
    using var connection = new MySqlConnection( 
        new MySqlConnectionStringBuilder(connectionString) 
        { 
            Database = string.Empty, 
            // AutoEnlist = false, 
            // Pooling = false, 
        }.ConnectionString); 
    connection.Open(); 
    return Parse(connection.ServerVersion); 
}

You then call this CustomAutoDetect(connectionString) method instead of the ServerVersion.AutoDetect(connectionString) one that ships with Pomelo.

If it suddenly works, than ServerVersion.AutoDetect(connectionString) is indeed the issue. Otherwise, it is not.

from pomelo.entityframeworkcore.mysql.

lauxjpn avatar lauxjpn commented on May 25, 2024

@pantonis Did you try the steps I outlined in my previous post?

from pomelo.entityframeworkcore.mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.