how to change metro app WINJS Sqlite database path - visual-studio-2012

i am developing windows8 application using HTML5 and Javascript. I am using SQLite3-WinRT database plugin, provided by GIT HUB https://github.com/doo/SQLite3-WinRT.
I have successfully integrated the plugin within my app and its working like charm, now the problem is I want to change the database path from
var dbPath = Windows.Storage.ApplicationData.current.localFolder.path + '\\database.sqlite';
to
var dbPath = \pages\js\ + '\\database.sqlite';

Well that path would be Windows.ApplicationModel.Package.current.installedLocation.path + "\\pages\\js\\database.sqlite"
You should however be aware that you cannot write into this location, just use it as a read-only database.
Have a look at the ATTACH command if you want to read data from a provisioned database in addition to having a read-write database.

Related

MongoDB and Mongoose databases not connecting across directories

I have a web server running, that uses mongoDB to store posts created on the website.
I would like to use a separate script to manage some things on the site, however for some reason I can't seem to get the code working across directories.
The website is running in /home/username/program/
I want my utility script to reside in /home/myname/utils/
This is currently the script I have:
#!/usr/bin/nodejs
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/db_name',{useNewUrlParser:true});
var chat = require('/home/username/project/lib/models/chat');
chat.findOne(function(err,doc) {
console.log(err,doc);
});
This code works, and gets data, but only if the file it's written it resides in /home/username/project/lib/.
If the file is in /home/mynameutil/ then it doesn't get any data at all. Why is this?
It is appropriate, because you don't start your project on /home/username so your program shared same instance, If you want to create something across the folder considers using workspaces.
Some tools make it easy to create workspaces like yarn and pnpm with this your code can be run in the same instance and share same node_modules. So you can use it across folder

Exporting sqlite3 db file from inside electron app. Is this possible?

I've got an app I've put together in Electron which saves data using sqlite3. Everything works as expected. I'd like to be able to export/save the actual database file so I can share it with others, treating it sort of like a save file.
I assume that if this is possible then I need to be using fs as well, which is fine.
Even better, can I just create the database file outside the compiled app from the start? And if so what's the best way to accomplish that?
Otherwise I can switch over to kripken/sql.js or something like that, but I'd rather not put the time in to make those changes if there's an easy way to just have the existing sqlite database file get saved to the user's computer outside the app.
I'm an idiot.
Instead of storing the file internally in the packaged app like this…
const dbPath = path.resolve(__dirname, 'data.db')
…I'm just storing it in the filesystem like this…
const {app} = require('electron').remote;
const dbPath = path.resolve(app.getPath('userData'), 'data.db');
…so that it's accessible from the start.
I'm leaving this question up because I'd be interested if there is a way to have a save file dialogue for an extant file in the packaged app, but in the mean time this is my answer.

SQL Server CE on Azure website

Trying to run SQL Server CE on an Azure website, but I am getting error:
Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details
You cannot use SQL Server CE on Azure Web Sites. Using Azure Web Sites you have to use external database - such as Azure SQL Database or MySQL.
Generally speaking for the cloud and any cloud service (IaaS, PaaS, SaaS), you shall never rely on local file system, but rather persist your files on a durable storage such as Azure Blob Storage. Thus you can't (shall not) use services like SQL Server CE.
This seems to work:
Reference System.Data.SqlServerCe 4.0, set "Copy Local" = true.
Azure runs as a an x86 process (not Amd):
Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
On dev machine find SQLServerCE dependencies:
C:\ProgramFiles\Microsoft SQL Server Compact Edition\v4.0\Private\x86
Create SqlServerCE\x86 folder in web project.
Copy x86 files into new x86 folder:
sqlceca40.dll
sqlcecompact40.dll
sqlceer40EN.dll
sqlceme40.dll
sqlceqp40.dll
sqlcese40.dll
Add this block to top of application_start in global.asax
string dest = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
string src = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "SqlServerCE\\x86";
foreach (var file in Directory.GetFiles(src))
{
var fileinfo = new FileInfo(file);
string destpath = Path.Combine(dest, fileinfo.Name);
if (!File.Exists(destpath))
{
fileinfo.CopyTo(destpath);
}
}
Note: I am not happy with this solution but I can't figure out how to get the files into the bin folder on deployment. post build events don't seem to work. If anyone has a better solution please suggest it.

Level DB data store gets recreated everytime

I am new to web app development, and still learning the basics. I am working on a basic application with nodejs and level db. Every time I restart my web application, the leveldb data store gets recreated, and the data that was stored in it is all gone.
My example code is below:
var level = require ('level');
var db = level('./mydb.db', {createIfMissing : true});
My understanding is that the db will get created only if it is missing.. otherwise the existing db would be used. In my case that is not happening.. what am I doing wrong?
Try the absolute path to the db while opening, it is possible the relative path is changing each time server runs.

Desktop Top Save Location For User Storage?

While writing a node-webkit application I came across needing to save users uploaded photos through the built in html file input. I can save photos easy enough where I wish via a nice post here on node file uploading and node-webkit's file dialog changes simple enough.
The question really is there a best practice for saving user generated content for a desktop app or is the application folder (OS specific) reasonable to use with say the application or company name? Security is not much of a concern here in this case.
node-webkit (at this time) has an application folder under under process.env.LOCALAPPPATH (for windows users anyway) which could be used.
Another option which is viable is to use an application directory in the exe directory of the program.
IE for node with process global.
var path = require('path');
var appDir = path.dirname( process.execPath ) + path.sep + 'data' + path.sep;
//might produce something like c:\\programs\\node-webkit\\data\\

Resources