sql-server-2012c++builder-xe6

I cannot get a value from a SQL server database with C++ Builder XE6


I'm using c++ builder XE6 and Microsoft SQL Server 2012 and I'm connected in my database but when I try to select a column I get an error this is my code

 int Recuperer_Num_Verssioning_Sqlserver ()
{
TSQLConnection   *co = new TSQLConnection(NULL);
Base_SQLServer *sqls = new Base_SQLServer()  ;
bool bl = sqls->Connecter(co);
String tn =   ":BASE.:DBO.T_SOCIETE" ;
String col = "NUM_1" ;
String sqlstring = "SELECT " + col + " FROM " + tn +"";
int num ;

if (bl)
   {
        TSQLQuery *req = new TSQLQuery(NULL) ;
        req->SQLConnection = co ;
        req->SQL->Clear() ;
        req->SQL->Add(sqlstring) ;
        req->Open() ;
       //   req-> ExecSQL() ;
        if (!req ->Eof)
                {
                 num =  (int) req ->Fields->Fields[0]->AsCurrency ;

                }
                delete req ;     
                delete co ;
                delete sqls ;

                return num ;

   }

return -1 ; 

}

After the opening I get the following error: SQL Error Code: 1087


Solution

  • I found the solution it was my SQL server 2012 user who hasn't have the right to get a result from the database.