Unable to connect to MYSQL using SQLAPI++

2019-09-15 00:18发布

I am new to working on SQLAPI++. I have everything installed, i.e. MYSQL, SQLAPI++ and I am using Code:Block++ as the editor for my C++ program. I was trying to connect to the database that I had created in the MYSQL, but I am unable to. I see the following error when I invoke Connect() written in SQLAPI++

Process returned -1-73741819(0xC0000005) execution time: 0.431s.

The MYSQL is running on my local machine on port no 3306.

int main(int argc, char* argv[])
{
    SAConnection con;
    SACommand cmd;
    int id =0;
    string name = "";
    cout<<"Error Thrown";
    try
    {
        con.Connect ("sampledb",
                     "root",
                     "abcd",
                     SA_MySQL_Client);
        std::cout<<"We are connected!\n";

        cout<<"Error Thrown";
        cmd.setConnection(&con);

        cmd.setCommandText("SELECT * FROM sampledb.table1");
        cmd.Execute();

        while(cmd.FetchNext())
        {
            id = cmd.Field("id").asLong();
            name = cmd.Field("name").asString();
            std::cout<<id;
            std::cout<<name;
        }

        con.Commit();

        con.Disconnect();
        std::cout<<"We are disconnected!\n";
    }

    catch(SAException &x)
    {

        try
        {

            con.Rollback ();
        }
        catch(SAException &)
        {
        }

        std::cout<<"Printing Error Text";
        printf("%s\n", (const char*)x.ErrText());
    }
    return 0;
}

The code compiles successfully. I am running on Windows 10 machine currently. I wonder what could be wrong with the above code. I have a doubt with the way we mention the database address in the Connect function or does it seem to be some other issue?

1条回答
beautiful°
2楼-- · 2019-09-15 00:55

I tried by installing everything again. This time I used CodeBlock 10.0.5, MySQL 5.5 and MySqlConnector C++ 1.1, and it worked without any issues this time around. Probably it was a compatibility issue earlier which was causing the exception. Earlier I had installed the latest version of CodeBlock, i.e. 16 and MySQL 5.7 along with the SQL connector

查看更多
登录 后发表回答