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

    Unanswered: MS SQL Server Database Connection Problems

    Hi

    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.

    how can i setup a default database.... Cause in my application i can't access my Test Database..... See code below

    Why is this code BOLD not working if i try to select a database ?

    Thank You
    Indian


    {
    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")); <- NOT WORKING... GETTING ERROR MESSAGE if i use this sql_statement " USE TEST; 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();

    }

  2. #2
    Join Date
    Sep 2003
    Posts
    522
    double-click on Administrator (login) and select the default database from the drop-down box at the bottom of this dialog box.

  3. #3
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    Better yet, use a more explicit query. Try:

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

  4. #4
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    Better yet, use a more explicit query. Try:

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

  5. #5
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    Sorry. Just replace the line in your code.

    You could also skip ODBC, and specify the database in your connection string by using OLEDB.

    Try this line in your code to connect to the server...

    //CDatabase object "db" created to connect database
    CDatabase db;
    db.OpenEx(_T("Provider=SQLOLEDB.1;Data Source=Beauty;Initial Catalog=Test;UID=Administrator"), CDatabase::noOdbcDialog);
    -bpd

  6. #6
    Join Date
    Sep 2003
    Posts
    30
    i figured it out

    thx
    Last edited by Indian; 09-30-03 at 11:21.

Posting Permissions

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