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

  • SEARCH
  • Home
  • 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 7248293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:07:08+00:00 2026-05-28T22:07:08+00:00

Given: A clean machine, no SQL Server CE present. A set of *.sdf files

  • 0

Given:

  • A clean machine, no SQL Server CE present.
  • A set of *.sdf files (Sql Server CE databases), never mind how they got there
  • The DLLs of the relevant Sql Server CE (sqlceca35.dll, sqlcecompact35.dll, sqlceer35EN.dll, sqlceme35.dll, sqlceoledb35.dll, sqlceqp35.dll, sqlcese35.dll)

Question:

  • How to make available the Sql Server CE OLEDB provider implemented by the aforementioned DLLs. I am looking for a programmatic way to do so when running as a limited account.

In other words, assuming we are talking about Sql Server CE 3.5, how to make the following code succeed:

IDBInitializePtr spDBInitialize;
HRESULT hr = spDBInitialize.CreateInstance(CLSID_SQLSERVERCE35, NULL);

Note, that the machine is clean and the code is running as a limited account.

EDIT

There is another catch. The code is C++, I cannot use Ado.NET

  • 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-28T22:07:08+00:00Added an answer on May 28, 2026 at 10:07 pm

    spDBInitialize.CreateInstance() does the following:

    1. Looks up your CLSID in the Windows Registry under HKEY_CLASSES_ROOT\CLSID
    2. Determines DLL from InProcServer
    3. Calls LoadLibrary() on the DLL
    4. Calls GetProcAddress for “DllGetClassObject”
    5. Calls DllGetClassObject to get an IClassFactory
    6. Uses returned IClassFactory to handle your CreateInstance(NULL, IID_IDBInitialize, (void**) &spIDBInitialize) request

    In your scenario, you do cannot get pass the first step because your DLL isn’t registered in the Windows Registry.

    However, because you know where the SQL Server CE DLLs are you can get around this by making your code just implement 3, 4, 5 and 6.

    Here’s a C++ console application that opens a SDF using CoCreateInstance replacement:

    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <oleauto.h>
    #include <atlbase.h>
    #include "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Include\sqlce_oledb.h"
    #include "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Include\sqlce_err.h"
    
    //----------------------------------------------------------------------
    // Creates a COM object using an HMODULE instead of the Windows Registry
    //----------------------------------------------------------------------
    
    HRESULT DllCoCreateInstance(HMODULE hModule, REFCLSID rclsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppv)
    {
        HRESULT hr = S_OK;
    
        if (hModule == NULL)
        {
            return E_INVALIDARG;
        }
    
        BOOL (WINAPI*DllGetClassObject)(REFCLSID, REFIID, LPVOID) = NULL;
        (FARPROC&) DllGetClassObject = GetProcAddress(hModule, "DllGetClassObject");
        if (DllGetClassObject == NULL)
        {
            return HRESULT_FROM_WIN32(GetLastError());
        }
    
        CComPtr<IClassFactory> spIClassFactory;
        hr = DllGetClassObject(rclsid, IID_IClassFactory, &spIClassFactory);
        if (FAILED(hr))
        {
            return hr;
        }
    
        return spIClassFactory->CreateInstance(pUnkOuter, riid, ppv);
    }
    
    //----------------------------------------------------------------------
    // Open a close a SDF file
    //----------------------------------------------------------------------
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        HRESULT hr = S_OK;
    
        hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    
        // Need a loaded library so we can CoCreateInstance without the Windows Registry.
        HMODULE hModule = LoadLibrary(L"C:\\Program Files (x86)\\Microsoft SQL Server Compact Edition\\v3.5\\sqlceoledb35.dll");
    
        // Open a SQL Server CE 3.5 database without using Windows Registry.
        CComPtr<IDBInitialize> spIDBInitialize;
        //hr = spIDBInitialize.CoCreateInstance(CLSID_SQLSERVERCE_3_5);
        hr = DllCoCreateInstance(hModule, CLSID_SQLSERVERCE_3_5, NULL, IID_IDBInitialize, (void**) &spIDBInitialize);
        CComPtr<IDBProperties> spIDBProperties;
        hr = spIDBInitialize->QueryInterface(IID_IDBProperties, (void**) &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();
    
        // @@TODO: Do your regular OLEDB code with the opened database.
        //...
    
        // Close COM objects
        spIDBInitialize = NULL;
    
        CoUninitialize();
        return 0;
    }
    

    Some things that’s missing from the code snippet:

    • Call FreeLibrary() when you’re completely finished with the library (usually prior to program termination)
    • Handle bad HRESULT hr return codes
    • Handle LoadLibrary() failures

    To get meaningful error messages for SQL Server CE operations you should consult Microsoft MSDN article Using OLE DB Error Objects (SQL Server Compact Edition). I usually start with a condense version of it here:

    if (FAILED(hr))
    {
        CComPtr<IErrorInfo> spIErrorInfo;
        GetErrorInfo(0, &spIErrorInfo);
        if (spIErrorInfo != NULL)
        {
            CComBSTR bstrError;
            spIErrorInfo->GetDescription(&bstrError);
            // @@TODO: Do stuff with bstrError
            wprintf("%s\r\n", (BSTR) bstrError);
        }
    }
    

    It’s easier and safer to just deploy the entire SQL Server CE 3.5 folder, but, if you want a minimal set, I believe the following files are the important ones for your scenario:

    • sqlceoledb35.dll – SQLCE OLEDB Provider
    • sqlceqp35.dll – SQLCE Query Processor
    • sqlcese35.dll – SQLCE Storage Engine
    • sqlceer35EN.dll – SQLCE Native Error Strings and Resources
    • sqlcecompact35.dll – SQLCE Database Repair tool

    For reference, the files I believe you don’t need are:

    • sqlceca35.dll – SQLCE Client Agent (for Merge Replication to SQL Server)
    • sqlceme35.dll – SQLCE Managed Extensions
    • System.Data.SqlServerCe.Entity.dll – Managed Assembly
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a data structure (e.g. a hash of hashes), what's the clean/recommended way to
Given a Python object of any kind, is there an easy way to get
We have a build machine running in our development department, which we've set up
Given a machine with 1 CPU and a lot of RAM. Besides other kinds
Following the guidelines given in Clean Code by Uncle Bob Martin, I'm trying to
Given a set of numbers and a set of binary operations, what is the
Given this class: public class MyClass { public int MyProperty {get; set;} } How
I've got a Windows 7 machine upon which I do both PHP/MySql Dev, and
Given a DataTable with Columns A, B, C, D looking for a clean way
Given that there is a function foo[A, B, C]( func: (a: A, b: B,

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.