Cannot open SQLite database in Windows 8 Store App - sqlite

I am trying to include SQLite database in my Windows 8 Store App (HTML/JS). I was following these tutorials:
http://www.youtube.com/watch?feature=player_embedded&v=luV6no8ti6M
http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx
At one point I added following code:
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "people.db");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
...
}
After deploying application I get following error:
Could not open database file: C:\Users\...\people.db (CannotOpen)
I looked up this path and file people.db was created, but apparently failed to open. What might be the reason for this?
I have also downloaded source code for this tutorial:
http://www.dzone.com/articles/getting-started-sqlite-windows
and got exact same exception - might there be something wrong with my computer configuration?

Actually your database file is in program files/program files(X86) after deploying your application where you have no rights by default to create, open & update existing file.
you cannot change this rights. As we are only allow to create folder inside the program files/program files(X86) directory.
If you change the directory (Except program files/program files(X86)) while installing then this may work very well.
refer
http://www.dzone.com/articles/getting-started-sqlite-windows

Related

Error during rendering of region Application Express - Sign In

I recently installed Oracle APEX and now trying to access APEX through
http://localhost:8080/.
When I access the page, I encounter this error. I am using Oracle Database 11g R2 and Apex Ver 18.1, I installed Oracle Data Services. When i did following step It shows me rendering error. I run following script to resolve image problem
reset_image_prefix.sql
Enter the Application Express image prefix [/i/] :/i/
my ord_params.properties file have following entry
**standalone.static.images=D\:\\ords.18.1.1.95.1251\\images**
Well, I know that running #apxldimg script helps in such a situation. Did you try it? As a parameter, it expects directory that contains the \apex directory. In the following example, full path to \apex directory is C:\5_apex_instalacija\apex4\apex.
It is a copy/paste from my Apex 4.x installation notes (didn't run it right now):
SQL> #apxldimg C:\5_apex_instalacija\apex4
PL/SQL procedure successfully completed.
old 1: create directory APEX_IMAGES as '&1/apex/images'
new 1: create directory APEX_IMAGES as 'C:\5_apex_instalacija\apex4/apex/images'

Login and account registration broken on MVC application

Hello I'm new to MVC and have been looking for a solution to my problem for the last couple days with no avail.
I've created a simple blog engine using ASP.NET MVC, after installing it on IIS on my local PC, I quickly realized I needed a database for the login service to work.
So I elected to use LocalDB on a PC that I plan to use as a server. I moved my files over to the PC and installed everything I needed. As soon as I installed SQLExpress with LocalDB and reset the site, everything was working perfectly. However, I noticed some minor typos on a section of the site that's not easily edited. Stupidly, I reinstalled the website entirely from a new build instead of just updating the view that needed correction like a smart person would do.
Now every time I attempt to login to an excising account or create a new one I simply get the error
Cannot attach the file 'C:\inetpub\wwwroot\App_Data\aspnet-FacetBlog-20161020065352.mdf' as database 'aspnet-FacetBlog-20161020065352'.
From what I've learned, It's something to do with my LocalDB instance, but fixes I've found online seem to have no effect.
Admittingly, I'm pretty naive with it comes to SQL, so hopefully the fix is simple. If I've failed to provide vital information please tell me and I'll update the question. Additionally, an explanation of what exactly went wrong would be much appreciated. Thank you for your time.
When reinstalling your site, probably you had deleted database file aspnet-FacetBlog-20161020065352.mdf in your database directory. Since deleting MDF file doesn't affect registered SQL Express instance, SQL Express thinks the database still exists and trying to connect but failed.
First, try to attach the DB using SSMS query like this:
EXEC sp_attach_db #dbname=N'aspnet-FacetBlog-20161020065352.mdf', #filename1=N'App_Data\aspnet-FacetBlog-20161020065352.mdf', #filename2=N'App_Data\aspnet-FacetBlog-20161020065352.ldf'
NB: I assumed your MDF file location stands in App_Data directory, change it to your actual database directory.
If attempt to attach by query doesn't work, try these steps:
Stop IIS/IIS Express pool if it still running.
Open a Windows Powershell instance on your server PC (install it first if doesn't exist).
Run the following command:
sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
sqllocaldb.exe start v11.0
Recreate the DB instance on your project, including data connection in Server Explorer (remove then create).
Re-run the project in development machine, then copy all required files to server PC. The database instance should be (re-)generated at this time.
Restart IIS/IIS Express pool on server PC.
Additionally you may run Update-Database command from Package Manager Console to ensure database integrity.
If those solutions still won't work altogether, simply rename your database files and attach it on your project, verify the connection string then retry step (5) and (6) above.
Related problems:
EF5: Cannot attach the file ‘{0}' as database '{1}'
Cannot attach the file ".mdf" as database "aspnet-"
Delete .mdf file from app_data causes exception cannot attach the file as database
Cannot attach the file 'C:\inetpub\wwwroot\MvcApplication10\App_Data\aspnet-MvcApplication10-20130909002323.mdf' as database 'aspnet-MvcApplication10-20130909002323'

How to configure Permissions: SQLite for ASP.Net Website?

I am trying to use SQLite for my ASP.Net Website.
The code is working fine in a Windows Application, but not in the WebAPP. I think I have to change some File Permissions to let the Website set up a Database. But how?
I always get a ERROR at the open() statement. Saying cannot open file.
Following the Code, which is working fine in the WindowsAPP:
Dim connDB as SQLiteConnection = New SQLiteConnection("PlayerDB.sqlite")
Dim conn = New SQLiteConnection("Data Source=PlayerDB.sqlite;Version=3")
conn.open() ---> ERROR
...
I hope someone can help me quick.
Thanks.
There are two reasons why you can get this error, so you must make sure that both these are taken care of before running your code.
You need to specify the absolute path to the database in your connection string and not a relative path that you are currently using in your code since SQLite database is just a file. For this you need to create a special folder for sqlite databases in your ASP.Net app. Let's say you have created a folder called sqlite under the root folder. Then your code should be as below. Server.MapPath is an utility method in ASP.Net framework to convert a root relative path to an absolute path that looks like c:\abc\wwq\myfile.db.
Dim connDB as SQLiteConnection = New SQLiteConnection(string.Format("Data
Source={0};Version=3;",Server.MapPath("~/sqlite/PlayerDB.sqlite")));
conn.open() ---> NO ERROR should happen now
You should also make sure that the ASP.Net application identity is allowed read/write access to thesqlitefolder created in above step under the root of your web app because data will be read as well as written to the database file under this folder.
Just right click on the sqlite folder and select Properties and then the Security tab as in screen shot below. In most localhost cases, the ASP.Net identity is IIS_IUSRS which is highlighted below. Make sure that this user has full control over the sqlite folder.

How to add database to setup in c#

I have made a setup for my C# application but when i installed it on another computer, it showed me an error that Path is invalid. I used the following code.
public string Path1 = (#"|DataDirectory|\MakeMyBill.sdf");
SqlCeConnection conn = new SqlCeConnection(Path3);
conn.Open();
if your application is running fine before creating setup and you are just asking the way to include database in setup then-
- I put the database with exe [in bin->debug folder]
- and while creating setup i put the database in Application folder with .exe.
[as you know there are 3 parts in file system -Application folder , user's desktop and user's program menu]

Where is SQLite database stored on disk?

Where is the SQLite database stored i.e. directory path on windows 7 when created ?
A SQLite database is a regular file. It is created in your script current directory.
.databases
If you run this command inside SQLite
.databases
it lists the path of all currently connected databases. Sample output:
seq name file
--- --------------- ----------------------------------------------------------
0 main /home/me/a.db
There is no "standard place" for a sqlite database. The file's location is specified to the library, and may be in your home directory, in the invoking program's folder, or any other place.
If it helps, sqlite databases are, by convention, named with a .db file extension.
If you are running Rails (its the default db in Rails) check the {RAILS_ROOT}/config/database.yml file and you will see something like:
database: db/development.sqlite3
This means that it will be in the {RAILS_ROOT}/db directory.
When you call sqlite3_open() you specify the filepath the database is opened from/saved to, if it is not an absolute path it is specified relative to your current working directory.
It depends on how you initialized the database. If you used the command line shell for SQLite (e.g. sqlite3 ex1) to create the database, it'll be a path from the root of your local machine. If you used a Python script to create the database, it'll be a path from your project.
To check the former, run the command line shell:
sqlite3
sqlite> .databases
To check the path in your project, you can print the path in the connection. For example:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASE = 'db'
def get_db_connection():
print(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn = sqlite3.connect(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn.row_factory = sqlite3.Row
return conn
In my case I think it was an access issue. I saved the SQLite files to "C:/Program Files (x86)/sqlite". I CD'd there, ran sqlite3, and created a database called test.db:
As you can see, I ran .database, which told me the .db file was created in the same directory, so I went to confirm in File Explorer, and it wasn't there:
Curiously the database was working correctly in spite of this.
It was only through trial-and-error that I discovered that I could save in some locations, but not others. It appears to me that SQLite can't save to locations that require elevation. In my case, moving from Program Files to My Documents made the issue go away.
I find it quite irritating that SQLite doesn't just tell me "access denied" instead of trying to be clever and saving to some location that I can't even find.
In Windows machines (Windows 2010), by default, the new SQLite database files will be stored in the same folder where Sqlite3.EXE application is stored in your machine. However , we can create a new folder in Windows and within sqlite> prompt, you may use the .cd to change to the new working directory.
It is a good idea to give a .db file extension to the new database files that you create (even though it is not mandatory to have any file extension)
The SQLite command, .databases will show the default database "main" or currently created or currently opened database or all "attached" database files with file path. The .attach is useful to attach more than one database file to the current connection when we want to work with tables belonging to different databases.
Regards,
Biju Joseph N.,
Houston TX, USA (January 12, 2023)
the database path will be displayed, when using .databases
SQLite is created in your python directory where you installed the python.
SQLit Database is simply a file where your local data is stored on your local machine
In Windows 10 if in the prompt command the path where you start sqlite is
C:\users\USER_NAME
You can find it in the user home folder.
The .db file is stored where you start the sqlite command.
I hope this solve the issue

Resources