[FreeTDS][SQL Server]Invalid cursor state error when using 2 statements from a connection.

BALAKRISHNAN RAJKUMAR <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <CAJGqact7HNbrC6nQB1TnXe_nh1JNJWb=rwETrVoGbwTvaaXY3Q@mail.gmail.com>
Hi All,


        I am obtaining two handles from a connection and trying two execute
two queries on successive lines. While the first execute statement
succeeds, the second one reports this "invalid cursor state" error. Can we
use more thane one statement using the same connection in FreeTDS. Could
some one please clarify.

        Below is the code snipped and the ouput. Full code is attached with
this email.

         ret = SQLExecDirect(smt_handle1, (SQLCHAR*)"select * from
employee", SQL_NTS);

        if(ret != SQL_SUCCESS)
        {

                cout<< "\n SQLExecDirect failed ";
        }
        else
        {
                cout<< "\nSQLExecDirect success";
        }

        ret = SQLExecDirect(smt_handle2, (SQLCHAR*)"select * from
employee", SQL_NTS);


        if(ret != SQL_SUCCESS)
        {
                 char status[10];
                 SQLINTEGER err;
                 char msg[100];
                 SQLSMALLINT msglen;


SQLGetDiagRec(SQL_HANDLE_STMT,smt_handle2,1,(SQLCHAR*)status,&err,(SQLCHAR*)msg,100,&msglen);

                 cout<< "\n SQLExecDirect failed [" << msg << "]";
        }



Output:

[root@localhost OdbcClasses]# ./StatementTest

 SQLConnect success.
 SQLExecDirect success
 SQLExecDirect failed [[FreeTDS][SQL Server]Invalid cursor state]

Thanks,
Bala.

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
StatementTest.C (text/x-csrc, 1.6 KB)
#include <stdlib.h>
#include <iostream>
#include <string>

#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>

using namespace std;

char                     V_OD_stat[10]; 
SQLINTEGER               V_OD_err,V_OD_rowanz,V_OD_id;
SQLSMALLINT              V_OD_mlen;
char             V_OD_msg[200],V_OD_buffer[200];


int main(int argc, char** argv)
{

	SQLRETURN ret;

	SQLHENV env_handle;

	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env_handle);

	SQLSetEnvAttr(env_handle, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3, 0);

	SQLHDBC db_handle;

	SQLAllocHandle(SQL_HANDLE_DBC, env_handle, &db_handle);

	ret != SQLConnect(db_handle, (SQLCHAR*)"WinDSN", SQL_NTS, (SQLCHAR*)"raghav", SQL_NTS, (SQLCHAR*)"raghav", SQL_NTS);
	
	if(ret != SQL_SUCCESS)
	{
		string message;
		cout<< "\n SQLExecDirect failed [" << message.c_str()<< "]";
	}
	else
	{
		cout<< "\n SQLConnect success.";
	}		

	SQLHSTMT smt_handle1,smt_handle2;

	SQLAllocHandle(SQL_HANDLE_STMT, db_handle, &smt_handle1);

	SQLAllocHandle(SQL_HANDLE_STMT, db_handle, &smt_handle2);

	ret = SQLExecDirect(smt_handle1, (SQLCHAR*)"select * from employee", SQL_NTS);
	
	if(ret != SQL_SUCCESS)
	{
		cout<< "\n SQLExecDirect failed.";
	}		
	else
	{
		cout<< "\nSQLExecDirect success";
	}	

	ret = SQLExecDirect(smt_handle2, (SQLCHAR*)"select * from employee", SQL_NTS);


	if(ret != SQL_SUCCESS)
	{
		 char status[10];
                 SQLINTEGER err;
                 char msg[100];
                 SQLSMALLINT msglen;
                
		 SQLGetDiagRec(SQL_HANDLE_STMT,smt_handle2,1,(SQLCHAR*)status,&err,(SQLCHAR*)msg,100,&msglen);

 		 cout<< "\n SQLExecDirect failed [" << msg << "]";
	}		
	
	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.