Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    102
    Thanks
    28
    Thanked 4 Times in 4 Posts

    problem using TADOConnection in Builder 2007 C++

    Hi all I created a small utility class which isn't finished but it's comming soon D:

    I need a litle help on something hope you guys can help me.

    the problem is that I get an EAccessViolation and I dont know why.
    i'll comment where I get the EAccessViolation.


    CADOUtil.h
    PHP Code:
    //---------------------------------------------------------------------------

    #ifndef ADOUtilH
    #define ADOUtilH

    #include <string>
    #include <ADODB.hpp>
    #include <DB.hpp>

    class CADOUtil
    {
        public:
        
    CADOUtil();
        
    CADOUtil(std::string conString);
        
    bool TryConnection();
        
    bool TryConnection(std::string conString);
        
    void SetConnectionString(std::string conString);
        
    int DbQuery(std::string TSQLQuery);
        
    int DbQuery(std::string TSQLQuerystd::string conString);

        private:
        
    std::string m_ConnectionString;
        
    TADOConnection *m_Connection;
    };
    //---------------------------------------------------------------------------
    #endif 
    my .cpp file ( I just put the methodes that are used. )
    PHP Code:
    void CADOUtil::SetConnectionString(string conString)
    {
        
    m_ConnectionString conString;
    }

    bool CADOUtil::TryConnection()
    {
        try
        {
            
    OutputDebugStringm_ConnectionString.c_str() );
                              
    // LINE WITH EROR EAcessViolation
            
    m_Connection->ConnectionString m_ConnectionString.c_str();
            
    m_Connection->Open();
            
    m_Connection->Close();
            return 
    true;
        }
        catch( ... )
        {
            
    OutputDebugString("FAILED TO CONNECT TO DATABASE");
            return 
    false;
        }

    Where im calling from a constructor in another class.

    Thanks in advance.
    PHP Code:
    string ConString "Provider=Microsoft.Jet.OLEDB.4.0;";
        
    ConString += "C:\LCS32_BACKOFFICE_PROTOTYPE\Debug\lcsbo_test.mde;";
        
    ConString += "Persist Security Info=False";

        
    CADOUtil AdoUtil(ConString);
        
    AdoUtil.TryConnection(); 
    I have tryed casting also and it dosen't work.
    still does not work
    m_Connection->ConnectionString = (WideString)m_ConnectionString.c_str();

  • #2
    Regular Coder
    Join Date
    Oct 2008
    Posts
    102
    Thanks
    28
    Thanked 4 Times in 4 Posts
    The answer was

    just to add

    this->m_Connection = new TADOConnection(NULL);


  •  

    Posting Permissions

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