Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:51:30+00:00 2026-05-26T07:51:30+00:00

I am using the MySQL Embedded Library and using P/Invoke to call the necessary

  • 0

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;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:51:31+00:00Added an answer on May 26, 2026 at 7:51 am

    The mysql_server_init function does not report errors via the Win32 error reporting mechanism SetLastError() and GetLastError(). So, you can”t use Marshal.GetLastWin32Error() to obtain the last error. The embedded mysql database reports errors via the functions mysql_error() and mysql_errno(). However, those functions seem to only report errors AFTER a successful call to mysql_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:

    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] = null; 
    
        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; 
        } 
    }
    

    Errors regarding your configuration should be printed to the console window by the mysql_server_init() function.

    Hope, this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using mysql 5.1.41 and innodb I'm doing some data import, but can't use load
(Using MySQL 4.1.22) I can't get this query of mine to use an index
using mysql as database. I got this code from the previous answers to the
I am using MySQL and PHP . In my database I have this table
I am creating some RSS feeds using PHP (5.2) from a MySQL db specifically
i'm just curious about something.I'm using hsql in myproject (embedded of course).At some time
Using MySQL , I can do something like: SELECT hobbies FROM peoples_hobbies WHERE person_id
Using MySQL syntax and having a table with a row like: mydate DATETIME NULL,
Using MySQL syntax, how would I write a query to return the following (I
(Using MySQL and PHP) I have a search form that will allow my users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.