I am using the MySQL Embedded Library and using P/Invoke to call the necessary functions to start the server. We resolved some issues regarding it in this topic, however another issue has presented itself.
The mysql_server_init() function returns 0 if success, 1 if error. Unfortunately, in my code when it returns 1, and I use Marshal.GetLastWin32Error() the error code is 0. I am assuming that it is not picking up on the error being generated by mysql_server_init(), but I am at a loss as to how to find out where the problem is.
Here is the relevant code block…
[DllImportAttribute("libmysqld.dll", SetLastError = true)]
static extern int mysql_server_init(int argc, string[] argv, string[] groups);
static string[] server_options = new string[2];
static string[] server_groups = new string[3];
public static bool Start()
{
server_options[0] = "mysql_test"; // not used?
server_options[1] = "--defaults-file=./my.ini";
server_groups[0] = "client";
server_groups[1] = "server";
server_groups[2] = "\0";
if (mysql_server_init(2, server_options, server_groups) != 0)
{
int lastError = Marshal.GetLastWin32Error();
Console.WriteLine("MySQL Library Init Failed with error code: " + lastError);
return false;
}
Console.WriteLine("MySQL Library Started Successfully!");
return true;
}
The
mysql_server_initfunction does not report errors via the Win32 error reporting mechanismSetLastError()andGetLastError(). So, you can”t useMarshal.GetLastWin32Error()to obtain the last error. The embedded mysql database reports errors via the functionsmysql_error()andmysql_errno(). However, those functions seem to only report errors AFTER a successful call tomysql_server_init().I think the problem of your code lies in the way you terminate your server_groups array.
You should use “null” instead of “\0” to “terminate” your array:
Errors regarding your configuration should be printed to the console window by the
mysql_server_init()function.Hope, this helps.