Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:38:41+00:00 2026-05-28T23:38:41+00:00

Does anyone have a sample code that given the database file displays the names

  • 0

Does anyone have a sample code that given the database file displays the names of all the user tables there?

I am not interested in a .NET code, just the C++.

I am trying to grok OLE DB to do the task – rocket science seems child play in comparison.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:38:41+00:00Added an answer on May 28, 2026 at 11:38 pm

    I’m going to assume SQL Server CE 3.0/3.1 but, for your reference, here are provider strings I’m aware of:

    • SQL Server CE 3.0 / 3.1 – Microsoft.SQLLITE.MOBILE.OLEDB.3.0
    • SQL Server CE 3.5 – Microsoft.SQLSERVER.CE.OLEDB.3.5

    Also, I will be providing you with two code examples:

    • ICommandText on “SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES”
    • IDBSchemaRowset on DBSCHEMA_TABLES

    I’m providing you the samples as C++ console application and have used ATL to make the code short. The code is complete and working but does not include the necessary error checking of the HRESULT hr.

    Here’s the C++ console application sample for querying a SQL Server CE 3.0/3.1 database for executing “SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES” using ICommandText and IRowset:

    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <oledb.h>
    #include <atlbase.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        HRESULT hr = S_OK;
        hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    
        // Connect to SQL Server.
        CComPtr<IDBInitialize> spIDBInitialize;
        hr = spIDBInitialize.CoCreateInstance(OLESTR("Microsoft.SQLLITE.MOBILE.OLEDB.3.0"));
        CComPtr<IDBProperties> spIDBProperties;
        hr = spIDBInitialize->QueryInterface(&spIDBProperties);
        CComVariant varDataSource(OLESTR("InsertYourSampleDatabase.SDF"));
        DBPROP prop = { DBPROP_INIT_DATASOURCE, DBPROPOPTIONS_REQUIRED, 0, DB_NULLID, varDataSource };
        DBPROPSET propSet = {&prop, 1, DBPROPSET_DBINIT};
        hr = spIDBProperties->SetProperties(1, &propSet);
        spIDBProperties = NULL;
        hr = spIDBInitialize->Initialize();
    
        // Execute the query.
        CComPtr<IDBCreateSession> spIDBCreateSession;
        hr = spIDBInitialize->QueryInterface(&spIDBCreateSession);
        CComPtr<IDBCreateCommand> spIDBCreateCommand;
        hr = spIDBCreateSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**) &spIDBCreateCommand);
        spIDBCreateSession = NULL;
        CComPtr<ICommandText> spICommandText;
        hr = spIDBCreateCommand->CreateCommand(NULL, IID_ICommandText, (IUnknown**) &spICommandText);
        spIDBCreateCommand = NULL;
        hr = spICommandText->SetCommandText(DBGUID_SQL, OLESTR("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"));
        DBROWCOUNT cRowsAffected = 0;
        CComPtr<IRowset> spIRowset;
        hr = spICommandText->Execute(NULL, IID_IRowset, NULL, &cRowsAffected, (IUnknown**) &spIRowset);
        spICommandText = NULL;
    
        // Retrieve records.
        HROW hRow = NULL;
        HROW *rghRow = &hRow;
        DBCOUNTITEM cRowsObtained = 0;
        hr = spIRowset->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRowsObtained, &rghRow);
        while (hr == S_OK && cRowsObtained == 1)
        {
            // Fetch the TABLE_NAME field.
            struct
            {
                DBSTATUS dbTableNameStatus;
                ULONG nTableNameLength;
                WCHAR szTableName[128 + 1];
            } data = {0};
            DBBINDING Binding = {0};
            Binding.iOrdinal    = 1;
            Binding.obValue     = sizeof(DBSTATUS) + sizeof(ULONG);
            Binding.obLength    = sizeof(DBSTATUS);
            Binding.obStatus    = 0;
            Binding.pTypeInfo   = NULL;
            Binding.pObject     = NULL;
            Binding.pBindExt    = NULL;
            Binding.dwPart      = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE;
            Binding.dwMemOwner  = DBMEMOWNER_CLIENTOWNED;
            Binding.eParamIO    = DBPARAMIO_NOTPARAM;
            Binding.cbMaxLen    = (128 + 1) * sizeof(WCHAR);
            Binding.wType       = DBTYPE_WSTR;
            Binding.dwFlags     = 0;
            Binding.bPrecision  = 0;
            Binding.bScale      = 0;
            CComPtr<IAccessor> spIAccessor;
            hr = spIRowset->QueryInterface(IID_IAccessor, (void**) &spIAccessor);
            HACCESSOR hAccessor = NULL;
            hr = spIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1, &Binding, 0, &hAccessor, NULL);
            hr = spIRowset->GetData(hRow, hAccessor, &data);
            DBREFCOUNT cRefCount = 0;
            hr = spIAccessor->ReleaseAccessor(hAccessor, &cRefCount);
            spIAccessor = NULL;
    
            // @@TODO: Do something with data.szTableName and data.nTableNameLength
            _tprintf(_T("%s\n"), data.szTableName);
    
            // Fetch next row of data.
            hr = spIRowset->ReleaseRows(1, rghRow, NULL, NULL, NULL);
            cRowsObtained = 0;
            hr = spIRowset->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRowsObtained, &rghRow);
        }
    
        // Release everything
        spIRowset = NULL;
        spIDBInitialize = NULL;
    
        CoUninitialize();
        return 0;
    }
    

    Here’s the C++ console application sample for querying a SQL Server CE 3.0/3.1 database for browsing the tables using IDBSchemaRowset and IRowset (note that TABLE_NAME is now at iOrdinal 3 instead of 1):

    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <oledb.h>
    #include <atlbase.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        HRESULT hr = S_OK;
        hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    
        // Connect to SQL Server.
        CComPtr<IDBInitialize> spIDBInitialize;
        hr = spIDBInitialize.CoCreateInstance(OLESTR("Microsoft.SQLLITE.MOBILE.OLEDB.3.0"));
        CComPtr<IDBProperties> spIDBProperties;
        hr = spIDBInitialize->QueryInterface(&spIDBProperties);
        CComVariant varDataSource(OLESTR("InsertYourSampleDatabase.SDF"));
        DBPROP prop = { DBPROP_INIT_DATASOURCE, DBPROPOPTIONS_REQUIRED, 0, DB_NULLID, varDataSource };
        DBPROPSET propSet = {&prop, 1, DBPROPSET_DBINIT};
        hr = spIDBProperties->SetProperties(1, &propSet);
        spIDBProperties = NULL;
        hr = spIDBInitialize->Initialize();
    
        // Execute the query.
        CComPtr<IDBCreateSession> spIDBCreateSession;
        hr = spIDBInitialize->QueryInterface(&spIDBCreateSession);
        CComPtr<IDBSchemaRowset> spIDBSchemaRowset;
        hr = spIDBCreateSession->CreateSession(NULL, IID_IDBSchemaRowset, (IUnknown**) &spIDBSchemaRowset);
        spIDBCreateSession = NULL;
        CComVariant rgRestrictions[CRESTRICTIONS_DBSCHEMA_TABLES];
        // rgRestrictions[2] = OLESTR("CENSUS"); TABLE_NAME restriction
        rgRestrictions[3] = OLESTR("TABLE"); // TABLE_TYPE restriction
        CComPtr<IRowset> spIRowset;
        hr = spIDBSchemaRowset->GetRowset(NULL, DBSCHEMA_TABLES, CRESTRICTIONS_DBSCHEMA_TABLES, rgRestrictions, IID_IRowset, 0, NULL, (IUnknown**) &spIRowset);
        spIDBSchemaRowset = NULL;
    
        // Retrieve records.
        HROW hRow = NULL;
        HROW *rghRow = &hRow;
        DBCOUNTITEM cRowsObtained = 0;
        hr = spIRowset->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRowsObtained, &rghRow);
        while (hr == S_OK && cRowsObtained == 1)
        {
            // Fetch the TABLE_NAME field.
            struct
            {
                DBSTATUS dbTableNameStatus;
                ULONG nTableNameLength;
                WCHAR szTableName[128 + 1];
            } data = {0};
            DBBINDING Binding = {0};
            Binding.iOrdinal    = 3;
            Binding.obValue     = sizeof(DBSTATUS) + sizeof(ULONG);
            Binding.obLength    = sizeof(DBSTATUS);
            Binding.obStatus    = 0;
            Binding.pTypeInfo   = NULL;
            Binding.pObject     = NULL;
            Binding.pBindExt    = NULL;
            Binding.dwPart      = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE;
            Binding.dwMemOwner  = DBMEMOWNER_CLIENTOWNED;
            Binding.eParamIO    = DBPARAMIO_NOTPARAM;
            Binding.cbMaxLen    = (128 + 1) * sizeof(WCHAR);
            Binding.wType       = DBTYPE_WSTR;
            Binding.dwFlags     = 0;
            Binding.bPrecision  = 0;
            Binding.bScale      = 0;
            CComPtr<IAccessor> spIAccessor;
            hr = spIRowset->QueryInterface(IID_IAccessor, (void**) &spIAccessor);
            HACCESSOR hAccessor = NULL;
            hr = spIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1, &Binding, 0, &hAccessor, NULL);
            hr = spIRowset->GetData(hRow, hAccessor, &data);
            DBREFCOUNT cRefCount = 0;
            hr = spIAccessor->ReleaseAccessor(hAccessor, &cRefCount);
            spIAccessor = NULL;
    
            // @@TODO: Do something with data.szTableName and data.nTableNameLength
            _tprintf(_T("%s\n"), data.szTableName);
    
            // Fetch next row of data.
            hr = spIRowset->ReleaseRows(1, rghRow, NULL, NULL, NULL);
            cRowsObtained = 0;
            hr = spIRowset->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRowsObtained, &rghRow);
        }
    
        // Release everything
        spIRowset = NULL;
        spIDBInitialize = NULL;
    
        CoUninitialize();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have sample code to copy open (in-use and locked by another program)
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa
Does anyone have some sample code showing how to POST to a URL using
Does anyone have a hello world sample or tutorial for creating an Eclipse plugin
Does anyone have any recommendations of tools that can be of assistance with moving
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
Does anyone have a suggestion on how to create a system that allows me
Does anyone have a simple example of implementing an async validation rule in csla?
Does anyone have any good samples, resources, pointers etc. for C# Silverlight with RIA
I'm looking to write a simple proxy server in .NET. Does anyone have any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.