stumpdk / mysql.server Goto Github PK
View Code? Open in Web Editor NEWMysql standalone server for unit testing in C#
Mysql standalone server for unit testing in C#
Seems there's an issue when using the "pipe" Connection Protocol (NOTE: This is on Windows)
v1.1.0
v8.0.23
Error Message:
System.PlatformNotSupportedException : The option 'Protocol=pipe' is not currently supported.
Stack Trace:
at MySql.Data.MySqlClient.MySqlBaseConnectionStringBuilder.<>c.<.cctor>b__1_0(MySqlBaseConnectionStringBuilder msb, MySqlConnectionStringOption sender, Object value)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Item(String keyword, Object value)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(String connectionString)
at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)
at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString)
at MySql.Server.MySqlServer.waitForStartup()
at MySql.Server.MySqlServer.StartServer()
See #1
To prevent the test server from conflicting with any real server instance on the current machine, I would like to configure the test server to run on a custom port.
Something like passing a config object to StartServer
would be perfect.
Hello,
I tried to create a stored procedure and it gaves me the following error
2017-09-19T03:22:02.0367327Z ##[error]Error Message:
2017-09-19T03:22:02.0367327Z ##[error] Initialization method ControlAcceso.Models.BLL.Tests.DatabaseTests.TestInitialize threw exception. MySql.Data.MySqlClient.MySqlException: MySql.Data.MySqlClient.MySqlException: Table 'mysql.proc' doesn't exist.
2017-09-19T03:22:02.0367327Z ##[error]Stack Trace:
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
2017-09-19T03:22:02.0367327Z ##[error] at MySql.Data.MySqlClient.MySqlHelper.ExecuteNonQuery(MySqlConnection connection, String commandText, MySqlParameter[] commandParameters)
2017-09-19T03:22:02.0377323Z ##[error] at MySql.Data.MySqlClient.MySqlHelper.ExecuteNonQuery(String connectionString, String commandText, MySqlParameter[] parms)
2017-09-19T03:22:02.0377323Z ##[error] at ControlAcceso.Models.BLL.Tests.DatabaseTests.LevantarInstanciaMySQL() in d:\a\1\s\src\ControlAccesos\ControlAccesos.Tests\Database\DatabaseTests.cs:line 233
2017-09-19T03:22:02.0377323Z ##[error] at ControlAcceso.Models.BLL.Tests.DatabaseTests.TestInitialize() in d:\a\1\s\src\ControlAccesos\ControlAccesos.Tests\Database\DatabaseTests.cs:line 216
This is how I try to create it. The first two scripts are the ones that create the database and insert records in it
` MySqlServer dbServer = MySqlServer.Instance;
dbServer.StartServer();
//Creo la DB y la selecciono
MySqlHelper.ExecuteNonQuery(dbServer.GetConnectionString(), string.Format("CREATE DATABASE {0};USE {0};", TestDatabase));
//Ejecuto los scripts para crear las tablas llenarla de datos
string directorio = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
MySqlHelper.ExecuteNonQuery(dbServer.GetConnectionString(), File.ReadAllText(directorio + @"\..\ControlAccesos\Models\ControlAccesos.edmx.sql"));
MySqlHelper.ExecuteNonQuery(dbServer.GetConnectionString(), File.ReadAllText(directorio + @"\..\Scripts DB\Inserts.sql"));
MySqlHelper.ExecuteNonQuery(dbServer.GetConnectionString(), File.ReadAllText(directorio + @"\..\Scripts DB\SP_ValidarAcceso.sql"));`
Thanks
Expose ProcessId property. After Closing process search by Id and not by name. If more than one instance was running search by name gives appearance that process wasn't killed.
Can you update to a new version of mysqld.
The current version is not compatible with some of the servers.
I am looking specifically on mysql server latest 5.6.xx version
I tried to follow the example in a console app.
MySqlServer testServer = MySqlServer.Instance;
//testServer.StartServer();
testServer.StartServer(3206);
Errored out: Server could not be started.
I have mysql installed and running on port 3306. Because this temporary database uses the default port it is unable to run. Add option to set the port the service will run on.
Connecting to named pipe to address 127.0.0.1 stopped working without a reason. Got code tested with address changed to . (dot) and localhost and works. Gone deeper into MySql.Data lib and not providing IP address is better approach.
I'm using MySql.Server to test my DB functionality, and it works really well. Today I installed a real Mysql server on my machine to be able to test my application in a live setting, but suddenly all my tests stopped working.
The first issue is that MySql.Server tries to kill all mysqld processes. This fails for the real server since it (luckily) runs under a different account.
The real problem, though, is that the mysqld process that MySql.Server starts stops right away. I suppose it has to do with conflicting arguments:
http://dev.mysql.com/doc/refman/5.7/en/multiple-servers.html
Maybe it's possible to reconfigure my main server (I'll try that), but it feels as if MySql.Server should adapt to the environment rather than vice versa. Do you agree?
If you halt a unit test in the IDE without calling Shutdown, it is impossible to run a new test, since the MySqlServer.StartServer will fail. The reason it fails seems to be the line:
this.ExecuteNonQuery("CREATE DATABASE testserver;USE testserver;", false);
getting an exception saying that the database already exists. (Maybe this is caused by the fix of #1?)
For the moment I'm using the following work-around, but it would be nice if this was built into the MySqlServer.StartServer method:
public static void StartServer()
{
if (HasStartedTheServer)
return;
HasStartedTheServer = true;
var thisIsWhereWeAre = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).ToLower();
foreach (var process in Process.GetProcessesByName("mysqld"))
try
{
var processLocation = Path.GetDirectoryName(process.MainModule.FileName);
var processParent = Path.GetDirectoryName(processLocation).ToLower();
if (!thisIsWhereWeAre.StartsWith(processParent))
continue;
process.Kill();
for (var i = 0; i < 10; i++)
try
{
Thread.Sleep(50);
Directory.Delete(processLocation, true);
break;
}
catch
{
}
}
catch
{
}
MySqlServer.Instance.StartServer();
}
The following code:
var dbServer = MySqlServer.Instance;
Console.WriteLine("Starting");
dbServer.StartServer();
Console.WriteLine("Stopping");
dbServer.ShutDown();
Console.WriteLine("Starting");
dbServer.StartServer();
Gives:
Starting
Stopping
Starting
System.Exception: Could not start server process: The system cannot find the file specified
at MySql.Server.MySqlServer.StartServer()
I have MySql installed on my computer, and when i try to run my test , it throws error as below ;
> Server could not be started.Authentication to host '127.0.0.1' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'localhost' (using password: NO)
This my test code;
public override void CleanUp()
{
if (dbServer != null)
{
dbServer.ShutDown();
}
}
public override Func<DbConnectionConfiguration> Initialize()
{
dbServer = MySqlServer.Instance;
CleanUp();
dbServer.StartServer();//Throws exception
MySqlHelper.ExecuteNonQuery(dbServer.GetConnectionString(), "CREATE DATABASE TestDataBase;");
return () =>
{
return new DbConnectionConfiguration()
{
DataProvider = MySqlProviderInvariantName.ProviderName,
ConnectionString = dbServer.GetConnectionString("TestDataBase"),
};
};
}
This test runs well on PCs that mySql have not installed on it. It fails on PC that MySql server installed and running.
My question is , how can i make this test running even when there is MySql Server installed on the PC?
Thanks,
Hi
I am currently writing some unit tests where I need to verify some queries against a MySQL database.
Is it possible to upgrade this library to support .NET Core?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.