jbogard / Respawn

Intelligent database cleaner for integration tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyword not supported: 'port' for MySQL Connection string

ARM-Source opened this issue · comments

When passing a MySQL connection string with the port identifier we get the error:

Keyword not supported: 'port'
image

This happens even though I specified

_checkpoint = new Checkpoint() { DbAdapter = DbAdapter.MySql, TablesToIgnore = new [] { "__EFMigrationsHistory" } };

Heres how I fixed it
image
public class RespawnMySql : Checkpoint { public override async Task Reset(string connectionString) { using (MySqlConnection connection = new MySqlConnection(connectionString)) { await connection.OpenAsync(); await base.Reset((DbConnection) connection); } } }

Having the same issue with an .net 5.0 project

UPDATE Figured out what my problem was. I needed to add SchemasToInclude to my checkpoint.

So, I've got two MySQL schemas on my local server, one for an API and one for integration tests. I had to do a similar thing as OP did. However, when Reset is called, it's executing the delete script on BOTH databases, which is not ideal. When debugging the test, the connection string being used is clearly the test database connection string. So, I'm at a loss as to what I'm doing wrong or if this is a bug (maybe not with Respawn). Anyone else have this issue?

I got the same issue about port keyword not supported but for me it’s Postgresql. I need the port in connection string as it’s integration testing so I spin up lots of Docker contains with the port being the differentiator. The workaround by arm-source worked but it is a bug as port is perfectly valid in a postgresql connection string. Looked at bug reports I think it’s my issue should below. I try tomorrow on that one but looks like not a bug for postgresql

using (var conn = new NpgsqlConnection("ConnectionString"))
{
await conn.OpenAsync();

await checkpoint.Reset(conn);

}

The same issue happens when using Npgsql driver.

Hi just on the Npgsql driver the answer is just change the way on making the connection. When I read the documentation a bit more if its not SQL server you just need to change things a bit around the connection. What I did was below works perfectly. So the secret is make the connection with NpsqlConnectionm open it and then Checkpoint.Reset it. All your problems will go away.

public static async Task Respawn(string connectionString)
{
await using var conn = new NpgsqlConnection(connectionString);
await conn.OpenAsync();
await Checkpoint.Reset(conn);
}

You don't need port key actually
server=localhost,3306; works for me.