FreeTDS连接Sqlserver数据库批量提交数据

FreeTDS作为Sqlserver和Sybase数据库的c/c++连接库

 int main()  
{  
    char szUsername[32] = "sa";  
    char szPassword[32] = "123456";  
    char szServer[32] = "172.16.3.127:1433";  
    char szDBName[32] = "blue";  
    char sql[256];  
   
  
    //初始化db-library  
    dbinit();  
  
    //连接数据库  
    LOGINREC *loginrec = dblogin();  
    DBSETLUSER(loginrec, szUsername);  
    DBSETLPWD(loginrec, szPassword);  
    DBSETLCHARSET(loginrec, "UTF-8");  
    DBPROCESS *dbprocess = dbopen(loginrec, szServer);//连接数据库  
    if(dbprocess == FAIL)  
    {  
        printf("Conect to MS SQL SERVER fail, exit!\n");  
        return -1;  
    }  
    printf("Connect to MS SQL SERVER success!\n");  
  
    //绑定数据库  
    if(dbuse(dbprocess,szDBName) == FAIL)  
        printf("Open database failed!\n");  
    else  
        printf("Open database success!\n");  
  
   
    memset( sql, 0x00, sizeof(sql) );  
    sprintf( sql, "insert into dbmanage_log values('1','Jason','172.16.4.101','1','test insert','1')");  
    dbcmd(dbprocess, sql);   //将数据送入连接池  
  
    memset( sql, 0x00, sizeof(sql) );  
    sprintf( sql, "insert into dbmanage_log values('2','Jason','172.16.4.101','1','test insert','1')");  
    dbcmd(dbprocess, sql);  
    memset( sql, 0x00, sizeof(sql) );  
    sprintf( sql, "insert into dbmanage_log values('3','Jason','172.16.4.101','1','test insert','1')");  
    dbcmd(dbprocess, sql);  
 
    dbsqlexec(dbprocess); //提交数据

    //关闭数据库连接 
    dbclose(dbprocess);
    dbloginfree(loginrec);
    dbexit(); 

    return 0;  
}

测试过程发现,一次最多只能提交460条数据,目前还没找到什么原因。

你可能感兴趣的:(SQL,Server)