无法使用SQLAPI ++连接到MYSQL [英] Unable to connect to MYSQL using SQLAPI++

查看:169
本文介绍了无法使用SQLAPI ++连接到MYSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触SQLAPI ++。我已经安装了所有东西,即MYSQL,SQLAPI ++,并且我正在使用Code:Block ++作为我的C ++程序的编辑器。我试图连接到在MYSQL中创建的数据库,但是无法连接。当我调用以SQLAPI ++编写的Connect()时,看到以下错误

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++

进程返回了-1-73741819(0xC0000005)执行时间:0.431s。

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

MYSQL在本地计算机上的3306端口上运行。

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;
}

代码成功编译。我目前在Windows 10计算机上运行。我不知道上面的代码有什么问题。我对在Connect函数中提及数据库地址的方式感到怀疑,还是其他问题?

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?

推荐答案

我尝试通过重新安装所有内容。这次我使用了CodeBlock 10.0.5,MySQL 5.5和MySqlConnector C ++ 1.1,并且这次没有任何问题。可能是较早的兼容性问题导致了异常。早些时候,我安装了最新版本的CodeBlock,即16和MySQL 5.7以及SQL连接器

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

这篇关于无法使用SQLAPI ++连接到MYSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆