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
spDBInitialize.CreateInstance()
does the following:LoadLibrary()
on the DLLGetProcAddress
for "DllGetClassObject"DllGetClassObject
to get anIClassFactory
IClassFactory
to handle yourCreateInstance(NULL, IID_IDBInitialize, (void**) &spIDBInitialize)
requestIn 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:
Some things that's missing from the code snippet:
FreeLibrary()
when you're completely finished with the library (usually prior to program termination)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:
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:
For reference, the files I believe you don't need are: