I am developing a metro ui application and I would like to use SQLite for some internal data instead of JET in order to take advantage of some already-written code.
Howerver when I try to use sqlite3_open for opening a data base, it does not work. I get an error saying a cannot open the data base.
I believe some APIs used by the SQLite cannot be used on metro style application.
Can someone help me on this? At least say me how to identify what apis should be ported?
This code should work:
auto localAppDataParh = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
std::wstring path( localAppDataParh->Data() );
path += L"\\sample.db";
sqlite3* db;
int rc = sqlite3_open16( path.c_str(), &db);
I believe some APIs used by the SQLite cannot be used on metro style application.
might work(at least on Preview Release), but not permitted. Windows App Cert Kit says:
Error: This application failed the supported API check.
API CreateFileA in kernel32.dll is not supported for this application type.
API CreateFileW in kernel32.dll is not supported for this application type.
API DeleteFileA in kernel32.dll is not supported for this application type.
:
:
Try to open the database in the local folder. Here's a wrapper that works: http://sqlwinrt.codeplex.com/
There was just released a new WinRT SQLite3 variant, that is compatible with the Windows Store guidelines. See https://github.com/doo/SQLite3-WinRT
try this one (for UTF-8 database filenames only):
int ret = Sqlite3.sqlite3_open_v2("qq.db", out db, 1, "");
See sqlite.org for more details.
I have not tried sqllite in WinRT, but I think it should work. The most likely candidate is that you do not have the correct permissions to the file you are trying to open. Check to make sure you can open the file with a simple API like fopen(). If that fails, then it is a permissions issue. You need to have your database in a directory that your app has natural rights to. It can't be in the user's documents folder for instance.
Related
My goal is to create a COM interface in my Windows local service, written with C++/MFC, whose methods could be called from a Windows Script Host JScript code running under a logged in interactive user account.
For instance, if I have a test.js that can be started with credentials of a logged in user, that does the following:
var Obj = new ActiveXObject("myservice.somename");
var Result = Obj.MyMethod("some data");
and then have MyMethod function processed in my service & return a value.
I know it's a general concept. At this stage I'm curious if such is possible (from a Windows security stand-point, i.e. calling system service from a user process) and if so, if there's any sample code that I can use as a basis for this?
I'm assuming that it must be some COM interface, right? But usually those go into a DLL. I've never tried to put them in a service.
Thank you!
I'm posting it for my own future reference, in despite of the treatment I got in the comments to my original post. It would've saved me a day of search if someone pointed me to this article...
This CodeGuru article, "COM in plain C, Part 2" explains how to create a COM interface that can be called from the Windows Script Host. His IExample2 project shows how to create an in-proc DLL that hosts the COM interface that can be called from a VBScript included in the same project. Then regiexample2 and unregiexample2 projects also show how to register/unregister the COM interface. The VBScript can be easily adjusted to work with JScript in my OP.
One word of caution though, that project is intended to be used for installation on a 32-bit OS. For 64-bit OS, you will need to build and register a 64-bit version of the in-proc COM Dll. The registration part from a 32-bit process is similar to the one shown, except that one needs to include the KEY_WOW64_64KEY flag when opening/creating registry keys.
My app needs to write and maintain a log file and its not running in admin mode. My question is what path could my app write to in such a situation. How could I obtain that path ?
There are two good options:
Use the Windows Event Log. You can easily create your own log for your application (if you expect to generate a lot of messages), or you can just add the messages to the standard logs (if you expect to generate only a few, occasional messages).
Since this is a built-in feature, any technical person is going to know about it and be able to locate your log files easily. It's also very interoperable with centralized management systems.
Write to a text file saved in the Application Data directory. This is where applications are supposed to store non-user data files, since, as you mentioned, the application directory is not something you can assume write privileges to.
For a log file about stuff that is specific to a particular computer, I'd say that this is local (non-roaming) application data, so you want the Local App Data folder. I'm sure that there is a Qt wrapper for this, but in Win32, you would call the SHGetKnownFolderPath function, specifying the KNOWNFOLDERID value FOLDERID_LocalAppData.
Remember that this function allocates memory to store the returned string—you must free it with a call to CoTaskMemFree when you are finished.
Sample code:
// Retrieve the path to the local App Data folder.
wchar_t* pszPath = 0;
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pszPath);
// Make a copy of that path.
std::wstring path(pszPath);
// Free the memory now, so you don't forget!
CoTaskMemFree(static_cast<void*>(pszPath));
Refer to the SHGetKnownFolderPath API, probably using the FOLDERID_LocalAppData option.
In my Silverlight application I am getting this error:
File operation not permitted. Access to path 'D:\ocean.gif' is denied.
Can anyone tell me why?
By default, you are not allowed to access the local file system from a Silverlight application; only the isolated file storage is available for standard Silverlight applications.
You may configure your Silverlight application to use elevated trust. This will give your SL application full access to the local file system. This is normally most practical for out-of-browser applications; there are many deployment restrictions associated with in-browser elevated-trust applications.
UPDATE Another alternative that normally do not require you to set elevated-trust is to read the image as a FileStream using the OpenFileDialog:
var dlg = new OpenFileDialog();
if (dlg.ShowDialog().GetValueOrDefault())
{
var stream = dlg.File.OpenRead();
... read the stream using a suitable image reader class ...
}
Right out of my head I cannot point out sufficient image stream readers that work in Silverlight, but try Googling for it.
To use elevated-trust in your applications, simply enable elevated-trust in your project. This is described in detail in the MSDN documentation.
Where can I obtain high quality information about ODBC & Access Databases?
I have worked on various projects over the years using ODBC from MFC/C++/Java.
Currently, I have a project in C++/MFC that uses a customized MFC layer to interface dynamically to an ODBC DSN connected to an Access 2000 dbm file.
This generally works.
However, I commonly get warnings such as:
DBMS: ACCESS Version: 04.00.0000 ODBC Driver Manager Version:
03.80.0000 Optional feature not implemented State:S1C00,Native:106,Origin:[Microsoft][ODBC Microsoft Access
Driver]
Warning: Driver does not support requested concurrency. Optional
feature not implemented
State:S1C00,Native:106,Origin:[Microsoft][ODBC Microsoft Access
Driver]
and now, I get the following when our software attempts to create a view:
General Warning Unable to open registry key 'Temporary (volatile) Jet
DSN for pr ocess 0x18fc Thread 0xc0 DBC 0x8c4cfc Jet'.
State:01000,Native:1,Origin:[Microsoft][ODBC Microsoft Access Driver]
DBMS: ACCESS Version: 04.00.0000 ODBC Driver Manager Version:
03.80.0000 Executing SQL: create view SPEC as select CALNAME as TEST, CARDNUMBER, CARTONSTYLE as CARTON, CCAL as FLUTE, CORRDIR,
CUSTOMERID, DESCRIPTION as DESCRIPTIO, DESIGNER, DESIGNNUM, JOINTSIZE,
JOINTTYPE, PANEL_D as DEPTH, PANEL_L as LENGTH, PANEL_W as WIDTH,
RULRULX as DSIZEX, RULRULY as DSIZEY, SHEETUX as SIZEX, SHEETUY as
SIZEY, SHEETX as GROSSX, SHEETY as GROSSY from "Designs" where
DESIGNNUM is not null
Warning: ODBC Success With Info, Driver's
SQLSetConnectAttr failed State:IM006,Native:0,Origin:[Microsoft][ODBC
Driver Manager]
General Warning Unable to open registry key 'Temporary (volatile) Jet
DSN for pr ocess 0x18fc Thread 0xc0 DBC 0x8c4cfc Jet'.
State:01000,Native:1,Origin:[Microsoft][ODBC Microsoft Access Driver]
For the first part, regarding warnings concerning optional feature not implemented, and concurrency state not implemented (perhaps the same underlying issue), I have no idea what concurrency feature my software is even asking for? What concurrency states are appropriate? How does one ask for the "correct" one? Is there a table for versions of Windows vs. appropriate concurrency state to request?
For the second part, regarding the specific failure to create a view due to failure to open a registry key: huh?! Who is failing to open what registry key?
I have found some information concerning the need to give IUSR full permissions on the "windows NT temp folder". This sounds like a horrible issue for a desktop application to need to concern itself with. How should a desktop application, using an ODBC DSN ever need to concern itself with user permissions when manipulating a database file which exists in a user read/write-able path? What more permissions are necessary to allow the user to execute this SQL? And since the user is already able to add and delete columns and rows in the existing tables in the database, what more needs to be done?
This code used to work under XP. So I have to assume that Vista and/or Win 7 added some security that now blocks this functionality.
I am interested in:
Canonical reference material from Microsoft that actually documents their various ODBC Access interfaces, options, versions, host-issues, etc.
Specific information regarding the warnings regarding concurrency.
Specific information regarding the apparent permissions failures when trying to create a view in the access 2000 dbm.
Suggestions for modernizing the above, sans a complete overhaul or technology replacement. i.e. I would happily update the Access file to 2003 or 2007 or whatever, or possibly switch the back-end to SQL Server Lite, but I cannot justify changing from ODBC to some replacement middleware (it's just not worth the time & risk).
Thanks for any ideas or help you may have to offer.
we have an application that dynamically make use of ODBC access databases.
Microsoft has good documentation about odbc
http://msdn.microsoft.com/en-us/library/s9ds2ktb(v=vs.80).aspx
You should also take a look at the CRecordset and CDatabase documentation
http://msdn.microsoft.com/en-us/library/1hkkwdf0(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/2dhc1abk(v=VS.80).aspx
For the concurrency issue, it often occurs when you open a CRecordset with the wrong options. Where I work, we usually open recordsets with the following options
RecordsetToUse.Open(CRecordset::dynaset, "SQL Statement or NULL to use the DefaultSQL", CRecordset::skipDeletedRecords);
If using the recordset for fast readonly access, you can also use
RecordsetToUse.Open(CRecordset::forwardOnly, "SQL Statement or NULL to use the DefaultSQL", CRecordset::readOnly);
3 . For the Create View problem, It seems that ODBC doesn't support the creation of views... I think, on the other hand, that you could use ADODB (http://www.codeproject.com/KB/database/adoclasses.aspx) to do that
Yeah, the migration of remote clients can be a pain. Part of the reason why I absolutely try to avoid Access at all costs. I've done this one of two ways.
Use WebEx (or some other online meeting program) to grab control of the remote machine to insure the migration goes as needed.
Build into the new code a check to see if database has been migrated.
If the new DB (SQL Server) shows as not found, then the app fires off the migration tool. However, this means building and perfecting a migration utility and scripts to automate the migration as nay number of things can go wrong.
One thing I did start doing a while ago is building an app compatibility table into the DB. That way the code can check to make sure the DB schema version matches. I also include another table (encrypted) with all the necessary SQL to upgrade (migrate) the DB to the new version. That way, the app can determine that the DB needs to be migrated and can run through the scripts to do it.
I really hope this helps.
I have an C++ app I built which is registered as the default handler for a file with a specific extension. So when I download one of these files with Firefox from a website, it downloads it to a temp directory and then shell executes my app while passing the full path to the downloaded file on the command line.
What is the best way to figure out from the external app what the original download url of the file was, given only it's path on disk? Can I use XPCOM API calls to inspect the FireFox download manager database?
I've figured out that this data get's stored in the "%APPData%\Mozilla\Firefox\($profile)\downloads.sqlite" file which is a SqlLite db file, but I really rather not try to open this file directly as FireFox has an open write handle to the file while running.
After perusing the Mozilla developer center for a while, I ran accross the nsIDownloadManager service, which seems to be just the thing. But I can't seem to get access to it from XPCOM in a separate process?
Here's the code I am using:
nsresult rv;
//init XPCOM
nsCOMPtr<nsIServiceManager> servMgr;
rv = NS_InitXPCOM2(getter_AddRefs(servMgr), nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
//Get a download manager instance
nsCOMPtr<nsIDownloadManager> downloadMgr;
rv = servMgr->GetServiceByContractID(NS_DOWNLOADMANAGER_CONTRACTID,
nsIDownloadManager::GetIID(), getter_AddRefs(downloadMgr));
NS_ENSURE_SUCCESS(rv, rv);
When I run this, the GetServiceByContractID() call returns 0x8007000e, which is defined in nsError.h as NS_ERROR_OUT_OF_MEMORY. (which I find very weird).
Any ideas here? Am I barking up the right tree?
No, you can't access Firefox's XPCOM objects from an external process, and you also shouldn't open the sqlite database while Firefox has it open. I don't know that there's any straightforward way to do what you want without writing a Firefox extension that has access to the Firefox internals.
I'm a little hazy on the details right now, but, assuming that your download is served with a custom MIME type, it's possible to register a handler for that type; your handler can then cancel the download and pass the URL to your application.