Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    30

    Unanswered: Connection Problem

    Hi

    I've got a small problem and i can't figure it out. I can connect successfully to the Microsoft SQL Server "Beauty" (get also nonzero for successfull connection). If i run the application (see code below). I get following Error Message "Illegal Objectname 'TestTabelle' ". I double checked the SQL statement and it should be correct. Even the spelling of TestTabelle is right. For testing purposes I've also included 5-6 data records in the tabel.

    I try to connect via ODBC. I've created the database with MS SQL Enterprise Manager. Right Click -> Create New Database. I called it "Test" and created in "Test" a new Table, which is called "TestTabelle".

    I found information how i can connect to a ms sql server "Beauty", i've also found how i can connect to a table, BUT where is the information which Database ?`in my case it should be Test.

    Anyone can help ?
    Thank you


    {
    CDBVariant value;
    char sql_statement [2048] = "";

    //CDatabase object "db" created to connect database
    CDatabase db;
    db.OpenEx(_T("DSN=Beauty;UID=Administrator"), CDatabase::noOdbcDialog);

    //CRecordset object "rs" created to access and manipulate database records.
    CRecordset rs(&db);
    strcpy(sql_statement,_T("SELECT * FROM TestTabelle"));
    rs.Open(CRecordset::forwardOnly,sql_statement);

    //Get quantity from Database
    int n = rs.GetODBCFieldCount( );
    while(!rs.IsEOF())
    {
    for( int i = 0; i < n; i++ )
    {
    rs.GetFieldValue("index",value);
    m_Buy_List.InsertItem(i,LPCTSTR(value.m_pstring));

    rs.GetFieldValue("product",value);
    m_Buy_List.SetItemText(i,2,LPCTSTR(value.m_pstring ));

    rs.GetFieldValue("price",value);
    m_Buy_List.SetItemText(i,3,LPCTSTR(value.m_pstring ));
    }
    rs.MoveNext( );
    }

    //Close records access.
    rs.Close( );

    //Close database connection.
    db.Close();

    }
    Last edited by Indian; 09-26-03 at 10:44.

  2. #2
    Join Date
    Sep 2003
    Posts
    69
    Do you have a default database set? If not try this:

    Code:
    strcpy(sql_statement,_T("USE TEST; SELECT * FROM TestTabelle"));

  3. #3
    Join Date
    Sep 2003
    Posts
    30
    1. I dunno how i can set the "Test" Database as default on MS SQL Server

    2. If i type "USE TEST;" like you said iam getting a big compiler or error message



  4. #4
    Join Date
    Sep 2003
    Posts
    522
    ok, since modifying the logon properties appears to be not acceptible, try this:

    strcpy(sql_statement,_T("SELECT * FROM Test.dbo.TestTabelle"));

  5. #5
    Join Date
    Sep 2003
    Posts
    30
    thx ms

    i could modify the default settings... i will try this sql_statement too..

    but somehow i am getting the errors know where i try to access the tabel field.

    first one: index (int)
    second: product (varchar)
    third: price (float)

    i ddin't found any error. weird ?

Posting Permissions

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