CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Hi all

    I have a heap corruption problem in getting STL containers data through OCCI methods .
    For instance if i do an assignment of this type

    while(rs->next() )
    {

    SRecord r; '' struct object
    r.PDM_APPLICATION_NO= rs->getString(1);
    r.PDM_FIRST_NAME=rs->getString(2);; //Error Heap Corruption
    r.PDM_LAST_NAME= rs->getString(3);
    r.PDM_F_FIRST_NAME= rs->getString(4);
    }



    I use Visual C++8 (VS 2005)[Windows 32-bit] oracle 10.2.0.3.0


    I get information from oracle table 'sample'. In this table 11 fields and 100000 records. program run without error in release mode vs 2005. 12 thousand records are fatched and then Heap corruption problem message dispaly and exit from program.
    Last edited by Dhpatil1; January 30th, 2009 at 03:46 AM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Quote Originally Posted by Dhpatil1 View Post
    Hi all

    I have a heap corruption problem in getting STL containers data through OCCI methods .
    I see absolutely no STL in the code you posted. It isn't even real C++:
    Code:
    SRecord r; '' struct object
    What is that?

    But seriously, do you think that anyone can solve your problem, given so little information?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2007
    Posts
    74

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Yes, you need to add more
    ....add more till I am full
    Since I am enjoying my supper
    ....a single lone dish of fish spagetti.

    The struct is corrupted because
    ....1. Possibly the size is unknown
    ....2. Allocation fails
    ...some more still need adding

  4. #4
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    #define WIN32COMMON


    #include <iostream>
    #include <Time.h>
    #include <occi.h>
    using namespace oracle:cci;
    using namespace std;

    struct SRecord
    {

    string PDM_APPLICATION_NO;
    string PDM_FIRST_NAME;
    string PDM_LAST_NAME;
    string PDM_F_FIRST_NAME;
    string PDM_F_LAST_NAME;
    string PDM_SPOUSE_NAME;
    string PDM_DOB;
    string PDM_ADD_LINE_1_RES;
    string PDM_ADD_LINE_2_RES;
    string PDM_ADD_LINE_3_RES;
    string PDM_CITY_RES;


    };
    int main()
    {

    char tmpbuf[128];
    vector<SRecord> row1;

    try{
    _strtime(tmpbuf);
    cout<<endl<<" database open start"<<tmpbuf;

    Environment* env = Environment::createEnvironment(Environment::OBJECT);
    Connection* conn = env->createConnection( "system", "dedupe","" );
    _strtime(tmpbuf);
    cout<<endl<<" database open end"<<tmpbuf;



    //string sqlQuery = "select * from timetest";

    _strtime(tmpbuf);
    cout<<endl<<" dynaset open start"<<tmpbuf;

    Statement* stmt = conn->createStatement("select * from timetest");
    ResultSet *rs = stmt->executeQuery();
    _strtime(tmpbuf);
    cout<<endl<<" dynaset open end"<<tmpbuf;



    _strtime(tmpbuf);

    cout<<endl<<"select Start Time "<<tmpbuf;
    //ResultSet:tatus status;
    //while((status = rs->next()) == (ResultSet:ATA_AVAILABLE))

    int i=0;
    while(rs->next() )
    {


    SRecord r;

    r.PDM_APPLICATION_NO= rs->getString(1);
    r.PDM_FIRST_NAME= rs->getString(2);
    r.PDM_LAST_NAME= rs->getString(3); //string str = d->rs->getString(2);
    r.PDM_F_FIRST_NAME= rs->getString(4);
    r.PDM_F_LAST_NAME= rs->getString(5); // cout<<"ID : "<<r.id;
    r.PDM_SPOUSE_NAME= rs->getString(6); // cout<<" Name : "<<r.name <<endl;
    r.PDM_DOB=rs->getString(7);

    r.PDM_ADD_LINE_1_RES= rs->getString(8); //str=d->rs->getString(2);
    r.PDM_ADD_LINE_2_RES=rs->getString(9); //cout<<str ;
    r.PDM_ADD_LINE_3_RES= rs->getString(10);
    r.PDM_CITY_RES=rs->getString(11);


    row1.push_back(r);

    // cout<<i++<<endl;

    }

    _strtime(tmpbuf);
    cout<<endl<<" select End Time "<<tmpbuf<<endl;

    _strtime(tmpbuf);
    cout<<"Insert Start Time "<<tmpbuf<<endl;


    string str1;

    // vector<SRecord>::iterator i;
    stmt->setAutoCommit(true);
    //for (i = row1.begin(); i != row1.end(); i++)
    for( long iCtr=0 ; iCtr < row1.size() ; iCtr++)
    {

    SRecord &ObjRec1 =row1[iCtr];

    str1="INSERT INTO dest_timetest VALUES('" ;
    str1+= ObjRec1.PDM_APPLICATION_NO ;
    str1 += "','";
    str1 += ObjRec1.PDM_FIRST_NAME ;
    str1 += "','";
    str1 += ObjRec1.PDM_LAST_NAME;
    str1 += "','" ;
    str1 += ObjRec1.PDM_F_FIRST_NAME ;
    str1 += "','" ;
    str1 += ObjRec1.PDM_F_LAST_NAME ;
    str1 += "','" ;
    str1 += ObjRec1.PDM_SPOUSE_NAME ;
    str1 += "','" ;
    str1 += ObjRec1.PDM_DOB ;
    str1 += "','";
    str1 += ObjRec1.PDM_ADD_LINE_1_RES ;
    str1 += "','" ;
    str1 += ObjRec1.PDM_ADD_LINE_2_RES ;
    str1 += "','" ;
    str1 += ObjRec1.PDM_ADD_LINE_3_RES ;
    str1 +="','" ;
    str1 += ObjRec1.PDM_CITY_RES ;
    str1 +="' )";
    stmt = conn->createStatement(str1);
    stmt->execute();
    conn->terminateStatement(stmt);
    stmt =conn->createStatement("commit");
    stmt->execute();
    conn->terminateStatement(stmt);

    }

    _strtime(tmpbuf);
    cout<<endl<<"End Time "<<tmpbuf<<endl;
    env->terminateConnection(conn);

    Environment::terminateEnvironment(env);

    cout << "Closing connection." << endl;


    }
    catch(SQLException ex)
    {
    //cout<<"Exception thrown for createConnection"<<endl;
    cout<<"Error number: "<< ex.getErrorCode() << endl;
    cout<<ex.getMessage() << endl;
    }

    getchar();
    return 0;



    this is my code i run this code in vs 2005 using oracle 10g. this code run but when read data from table that time some record read and dispaly message Heap corruption problem .

    please help me

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    1) Please use proper code tags when posting code. The code you posted is almost unreadable.

    2) You didn't include <string>, but you're using it. Please include all of the proper headers.

    3) What is getString()? What does it do? What does it return (variable type and possible values)? What happens if the argument given to getString() is out of range or invalid? This is all of the information that you should be telling us and should know for yourself. I notice you do no check to see if getString() failed or whether the argument is valid. Isn't this something you should be doing?

    Just assigning a std::string isn't going to generate an exception unless you are attempting to assign a NULL to it. The problem is more than likely in getString(), which is why I asked you to provide more information on this function.

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    hi,

    getstring function of Resultset class of OCCI . This method returns the value of the attribute as a string. If the value is SQL NULL,the result is NULL.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Quote Originally Posted by Dhpatil1 View Post
    hi,

    getstring function of Resultset class of OCCI . This method returns the value of the attribute as a string.
    Is this OCCI a static library? A DLL? is it source code? If it's a static library or DLL, and it returns a std::string, then that version of OCCI must be built with the same version of Visual C++ that you're using for your application.

    The reason is that the std::string internals are different between versions of Visual C++. What could be happening is that the std::string that getString() returns isn't compatible with the std::string that the version of Visual C++ you're using is expecting. Therefore the crash.

    If the OCCI is source code that you just compile along with your application, then there shouldn't be an issue.
    If the value is SQL NULL,the result is NULL.
    What value is "NULL"? If it's 0, then you can't assign that to a std::string. Only valid strings can be assigned to a std::string using "=".

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Paul McKenzie thanks for your reply and valuable suggestion.

    when we install oracle many dlls are copied to home direcory of oracle.
    OCCI( oracle call for c++ interface) provides the means of comunication with the oracle through c++. It has 4 dlls to provide access to oracle database. like kpucb.dll,oci.dll,ociw32.dll,oraocci10.dll

    i have installed oracle10g on m/c(32bit).
    but i don't know in which vc++ version it is built.
    I have created the appl. in vs2005 (vc++ 8). and it is giving problem.

    but the strange thing is when i use that in vc++ 6.0, it works fine.
    I guess it is bcoz occi dlls are built in vc++6.0.

    And i think you are right. I am using it in vs2005(vc++8) that's why it is giving problem.

    Plz give me some solution.
    Thanks in Advance!!!

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Quote Originally Posted by Dhpatil1 View Post
    but the strange thing is when i use that in vc++ 6.0, it works fine.
    That's the problem. The std::string internals in VC 6.0 is vastly different than the one in VS 2005.
    Plz give me some solution.
    You have to contact Oracle and have them give you DLL's that are compatible with VS 2005. Since Oracle decided to use DLL's for their interface, they are responsible for providing you the proper DLL's that return types that are compatible for your compiler. I don't know what license agreements come into play, but I would be surprised that Oracle didn't have versions for VS 2005, since so many programmers use this version of VC++.

    If Oracle provided source code for their API, then there would be no problem -- all you would need to do is compile the source code for any compiler and it would work. If Oracle has an option to get the source code, I would recommend it to you so that you don't run into these problems again.

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    any one help me

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Quote Originally Posted by Dhpatil1 View Post
    any one help me


    Did you read my last post? What have you done to solve the problem? It is an Oracle issue, and I told you what you should be doing. Oracle's tech support is not here.

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Jan 2009
    Location
    India
    Posts
    13

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Yes,
    thanks for your reply and I totaly agree with you that it is oracle problem.

    But what it surprising is out of two dlls,
    oraocci10.dll is built in vc++8.0(2005)
    and oci.dll is built in vc++7.1(2003). ( I found it by using depends.exe )

    And i am not able to get the oci.dll built in vc++8.0.
    I have searched it on oracle site but they don't have it.

    If you find it somewhere plz lem me know.

  13. #13
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005

    Quote Originally Posted by Dhpatil1 View Post
    Yes,
    thanks for your reply and I totaly agree with you that it is oracle problem.

    But what it surprising is out of two dlls,
    oraocci10.dll is built in vc++8.0(2005)
    and oci.dll is built in vc++7.1(2003). ( I found it by using depends.exe )

    And i am not able to get the oci.dll built in vc++8.0.
    I have searched it on oracle site but they don't have it.
    Then send an email to Oracle or call them up or whatever, and demand they build oci.dll with version 8.0 of the compiler.

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Heap corruption problem in getsrtring() of resultset occi methods in vs 2005


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured