problem with ODBC DATABASE
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: problem with ODBC DATABASE

  1. #1
    Join Date
    Sep 2011
    Posts
    10

    problem with ODBC DATABASE

    Why after creating project MFC with database support and adding database that i created with foxpro 9 all time property m_nFields = 0;
    After that i get Assertion failure if i stat debugging?
    Ananother words project say that my database is empty but that really not empty ?
    database is dbf.
    I added that by start -> Administrative Tools -> Data Sources (ODBC) -> User-DSN-> Add
    Microsoft dBase Driver (*.dbf)
    after that added fule in mfc application wizzard ?
    Help please ?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: problem with ODBC DATABASE

    m_nFields is a CRecordset member. Did you derive a class fro CRecordset? How are you trying to use it?

  3. #3
    Join Date
    Sep 2011
    Posts
    10

    Re: problem with ODBC DATABASE

    yes its a CRecordset
    Code:
    IMPLEMENT_DYNAMIC(Cstep111_newSet, CRecordset)
    
    Cstep111_newSet::Cstep111_newSet(CDatabase* pdb)
    	: CRecordset(pdb)
    {
    	m_nFields = 0;
    	m_nDefaultType = snapshot;
    }
    as i understand after adding database in application wizard of MFC . MFC must recognize database and give code like
    Code:
    CTestMemoSet::CTestMemoSet(CDatabase* pdb)
    	: CRecordset(pdb)
    {
    	//{{AFX_FIELD_INIT(CTestMemoSet)
    	m_NAME = _T("");
    	m_DAY = _T("");
    	m_nFields = 2;
    	//}}AFX_FIELD_INIT
    	m_nDefaultType = snapshot;
    }
    Here we see that he recognized 2 fields , after that MFC give them names m_NAME and m_DAY
    I dont understand why after that code (in that project)
    Code:
    CString Cstep111_newSet::GetDefaultConnect()
    {
    	return _T("DSN=foxpro_database;UID=;PWD=;SourceDB=h:\\\x05d4\x05de\x05e1\x05de\x05db\x05d9\x05dd \x05e9\x05dc\x05d9\\Visual FoxPro Projects;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;");
    }
    I get first example and not second of constructor.
    i also see here Null=Yes;Deleted=Yes; but it not null and not deleted .
    i add it in application wizard like
    Database Support -> database view without file support-> Client type :ODBC->CHECKED bind all columns->TYPE:snapshot
    CLICK data source ->from computer ->click OK
    CHECK Database type Free Table Directory
    browse my database employees.dbf
    click ok
    select from Tables my table employees ,click OK
    IT all
    what i did wrong ?

  4. #4
    Join Date
    Sep 2011
    Posts
    10

    Angry Re: problem with ODBC DATABASE

    I am trying build application that can retrieve data from my database . change data by use of my application , add data .

  5. #5
    Join Date
    Sep 2011
    Posts
    10

    Angry Re: problem with ODBC DATABASE

    yes
    in my code i have
    #include "stdafx.h"
    #include "step111_new.h"
    #include "step111_newSet.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif


    // Cstep111_newSet implementation

    // code generated on יום*רביעי 28 ספטמבר 2011, 03:20

    IMPLEMENT_DYNAMIC(Cstep111_newSet, CRecordset)

    Cstep111_newSet::Cstep111_newSet(CDatabase* pdb)
    : CRecordset(pdb)
    {
    m_nFields = 0;
    m_nDefaultType = snapshot;
    }

    CString Cstep111_newSet::GetDefaultConnect()
    {
    return _T("DSN=foxpro_database;UID=;PWD=;SourceDB=h:\\\x05d4\x05de\x05e1\x05de\x05db\x05d9\x05dd \x05e9\x05dc\x05d9\\Visual FoxPro Projects;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;");
    }

    CString Cstep111_newSet::GetDefaultSQL()
    {
    return _T("[employees]");
    }

    but after add database in application wizard it must bee like that
    IMPLEMENT_DYNAMIC(CTestMemoSet, CRecordset)

    CTestMemoSet::CTestMemoSet(CDatabase* pdb)
    : CRecordset(pdb)
    {
    //{{AFX_FIELD_INIT(CTestMemoSet)
    m_NAME = _T("");
    m_DAY = _T("");
    m_nFields = 2;
    //}}AFX_FIELD_INIT
    m_nDefaultType = snapshot;
    }

    CString CTestMemoSet::GetDefaultConnect()
    {
    return _T("ODBC;DSN=TestDB");
    }

    CString CTestMemoSet::GetDefaultSQL()
    {
    return _T("[FRIEND]");
    }
    i dont know why my program dont recognized any fields in database. however i have 2 fields ?
    what i did wrong ?

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: problem with ODBC DATABASE

    You need to add some fields to Cstep111_newSet. The wizard should have added them for you unless you unchecked the bind all fields checkbox.

  7. #7
    Join Date
    Sep 2011
    Posts
    10

    Red face Re: problem with ODBC DATABASE

    Hi
    I unchecked bind all fields but it dont helped. I get also m_nFields = 0
    so i do it manually i changed all code like
    IMPLEMENT_DYNAMIC(Cstep_111Set, CRecordset)

    Cstep_111Set::Cstep_111Set(CDatabase* pdb)
    : CRecordset(pdb)
    , Name(_T(""))
    , Birthday(_T(""))
    {
    m_nFields = 2;
    m_nDefaultType = snapshot;
    }
    //#error Security Issue: The connection string may contain a password
    // The connection string below may contain plain text passwords and/or
    // other sensitive information. Please remove the #error after reviewing
    // the connection string for any security related issues. You may want to
    // store the password in some other form or use a different user authentication.
    CString Cstep_111Set::GetDefaultConnect()
    {
    return _T(/*"DSN=TestDB;DBQ=H:\\המסמכים שלי\\Visual FoxPro Projects;DriverId=277;FIL=dBase IV;MaxBufferSize=2048;PageTimeout=600;"
    Why it dont work ? Dont understand

    */
    //Use another driver that i downloaded from foxpro
    "DSN=foxpro_database;UID=;PWD=;SourceDB=h:\\\x05d4\x05de\x05e1\x05de\x05db\x05d9\x05dd \x05e9\x05dc\x05d9\\Visual FoxPro Projects;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;");
    }

    CString Cstep_111Set::GetDefaultSQL()
    {
    return _T("[employees]");
    }

    void Cstep_111Set:oFieldExchange(CFieldExchange* pFX)
    {
    pFX->SetFieldType(CFieldExchange:utputColumn);
    RFX_Text(pFX, _T("[Firstname]"), Name );
    RFX_Text(pFX, _T("[Birthdate]"),Birthday);
    // Macros such as RFX_Text() and RFX_Int() are dependent on the
    // type of the member variable, not the type of the field in the database.
    // ODBC will try to automatically convert the column value to the requested type

    }
    Now everything fine.
    i ADDED 2 edit fields connected them to database
    void Cstep_111View:oDataExchange(CDataExchange* pDX)
    {
    CRecordView:oDataExchange(pDX);
    // you can insert DDX_Field* functions here to 'connect' your controls to the database fields, ex.
    // DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet);
    // DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet);
    // See MSDN and ODBC samples for more information
    DDX_FieldText (pDX ,IDC_EDIT1 ,m_pSet ->Name ,m_pSet );
    DDX_FieldText(pDX ,IDC_EDIT2 ,m_pSet->Birthday ,m_pSet );
    }

    Now i can see information in my fields .
    Thank you .
    You help me. !!!

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: problem with ODBC DATABASE

    I'm glad you got it working, but you should leave bind all fields checked. Perhaps my post wasn't clear.

  9. #9
    Join Date
    Sep 2011
    Posts
    10

    Angry Re: problem with ODBC DATABASE

    Why if i try add new note function m_pSet->Update(); newer work all time i get message
    "Cannot add a new record!"
    void Cstep_111View::On_ADD_BUTTON(void)
    {

    /*CWnd *myEdit =GetDlgItem (IDC_EDIT1 );
    CString strin;
    m_pSet->AddNew ();
    GetDlgItemText (IDC_EDIT1 ,strin);
    m_pSet->Name =strin;
    m_pSet->Update ();
    m_pSet->Requery ();//функция Requery перечитывает набор данных

    UpdateData(false);*/
    if(m_pSet->CanAppend() == 0)

    AfxMessageBox(_T("You can only read error add new member"));



    ASSERT(m_pSet);
    if ( !m_pSet->CanUpdate())
    {
    AfxMessageBox(_T("Cannot add a new record!"));
    return;
    }
    m_pSet->AddNew();
    m_pSet->Name =m_pSet->GetMaxID ();

    // m_pSet->Name="Hello";

    m_pSet->Update();

    m_pSet->Requery();
    m_pSet ->MoveLast ();
    UpdateData(FALSE);



    }

    if someone can say possible cause ?
    database is not read only . ?

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: problem with ODBC DATABASE

    What kind of database is it? How are you opening it? Does it have a primary key defined?

    You may want to catch a CDBException that would be thrown to get more detailed information.

  11. #11
    Join Date
    Sep 2011
    Posts
    10

    Unhappy Re: problem with ODBC DATABASE

    1)This database that i did in foxpro9 . employees.dbf
    2)I am open it by
    CString Cstep_111Set::GetDefaultConnect()
    {
    return _T(/*"DSN=TestDB;DBQ=H:\\המסמכים שלי\\Visual FoxPro Projects;DriverId=277;FIL=dBase IV;MaxBufferSize=2048;PageTimeout=600;"
    Why it dont work ? Dont understand

    */
    //Use another driver that i downloaded from foxpro
    "DSN=foxpro_database;UID=;PWD=;SourceDB=h:\\\x05d4\x05de\x05e1\x05de\x05db\x05d9\x05dd \x05e9\x05dc\x05d9\\Visual FoxPro Projects;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;");
    }

    CString Cstep_111Set::GetDefaultSQL()
    {
    return _T("[employees]");
    after that i can see data in my 2 edit boxes
    DDX_FieldText (pDX ,IDC_EDIT1 ,m_pSet ->Name ,m_pSet );
    DDX_FieldText(pDX ,IDC_EDIT2 ,m_pSet->Birthday ,m_pSet );
    3)Primary key its 1 column "Firstname"
    4) in imeediate window i see
    First-chance exception at 0x7c812afb in step_111.exe: Microsoft C++ exception: CDBException at memory location 0x0012f318.
    programm say that it cant find a database ?
    but why if i can retrieve data and see it in edit boxes ?

  12. #12
    Join Date
    Sep 2011
    Posts
    10

    Re: problem with ODBC DATABASE

    it a full text
    DBMS: Visual FoxPro
    Version: 03.00.0000
    ODBC Driver Manager Version: 03.52.0000
    First-chance exception at 0x7c809f52 in step_111.exe: 0xC0000005: Access violation reading location 0x00000003.
    First-chance exception at 0x7c809f52 in step_111.exe: 0xC0000005: Access violation reading location 0x00000001.
    Warning: no message line prompt for ID 0x8003.
    Error: must enter Edit or AddNew mode before updating.
    Failed to Update or Delete.
    First-chance exception at 0x7c812afb in step_111.exe: Microsoft C++ exception: CDBException at memory location 0x0012f318..
    Warning: Uncaught exception in WindowProc (returning 1).

    but i put AddNew before ?
    What a problem ?

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,480

    Re: problem with ODBC DATABASE

    Instead of just running the program and letting it crash, why not step through the code in the debugger?

  14. #14
    Join Date
    Sep 2011
    Posts
    10

    Re: problem with ODBC DATABASE

    IF it is not clear . program crash in Update () function. Are you think i am not check where it is crush?

  15. #15
    Join Date
    Sep 2011
    Posts
    10

    Re: problem with ODBC DATABASE

    I think its problem with driver. Because i did all with Access and PostgreSQL .SDI and Dialog . Its work .Only with foxpro 9 not .

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center