开发者

Dual connection to sql server in c code

I'm working on a project in C with MySQL

I'm having a problem connection to the MySQL server. First have one time a connection, this works.

But now in an other section an also need to retrieve info from the db

There I use the same code to connect.

conn = mysql_init(NULL);
//check if there is a connection
if (conn == NULL)
{
    printf("Error %u: %s\n", mysql_errn开发者_运维问答o(conn), mysql_error(conn));
    exit(1);
}
if (mysql_real_connect(conn, "localhost", "test", "test", "test", 0, NULL, 0) == NULL)
{
    printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
}

But when I use this a second time, I get an error

Unhandled exception at 0x009818c9 in simple.exe: 0xC0000005: Access violation reading location 0x00000000.

it crashes on the if(conn == NULL)

Anyone got an idea why this don't work?


That seems to be windows's version of a segmentation fault (I've never compiled anything on windows), so, check your pointers and make sure they aren't null, and if they are to be global, make sure they are on the heap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜