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

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.

Related

shared folder route in ASP.Net, Framework 2.0

I have this problem:
I have a web application that was working ok on accessing shared folder in same server application, but outside of application folder.
The route of shared folder is stored in a table (SQL Server 2008 R2), this is query using sqlcommand and datareader, including credentials to access the shared folder.
Suddenly that part of application stop working, the problem I found is that the path of shared folder appears without the char '\', something like this \IP_SERVERsharedfolder altough in database it is stored as \\IP_SERVER\sharedfolder, if the query is executed on sql server managment, it displays the whole path.
Do you have experienced a similar problem.
I appreciate your help.
The problem here is not how to access the shared folder, that means, the problem is when the path is gotten from database where it is stored, I use a data reader object to get from database:
If dtrReader.HasRows Then
fldPath = dtrReader(3).ToString
username = dtrReader(4).ToString
password = dtrReader(5).ToString
End If
in variable fldPath , I got \IP_SERVERsharedfolder instead \\IP_SERVER\sharedfolder, char \ is removed.

Cannot open SQLite database in Windows 8 Store App

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

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]

How can I specify a RELATIVE JDBC SQLite url (path?)

I've been trying to get this work for two days and tried all suggestions that I could find. Alas, without success, so far.
This is what I'm trying to do: I am building a small (java swing) desktop database application. I'm using Netbeans 7.0 and SQLite, and found the JDBC driver from http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC to work fine as long as I specify an absolute path in the JDBC URL:
jdbc:sqlite://Users.../lib/db/ithildin.db
Here's how it looks in Netbeans' Services -> Databases tab, using an absolute URL:
opening the connection and then the tables node shows the available tables.
But because I intend to distribute this application to other people, using an absolute path is not going to work. From what I have read here and there it seems to be possible to also specify a relative path to the SQLite database file, but I cannot get it to work whatever I try.
The strange thing is that when I create a connection in Netbeans it initially seems to work when I put both the sqlite jdbc driver jar and the sqlite database file in a /db subdirectory in /lib (in the Netbeans project directory):
and when I open the new connection it maintains that illusion -
but when I open the "Tables" node it turns out to be empty:
Similary, this connection seems valid but as soon as I try to use it - for instance in "Generating Entity Classes From Database" it tells me that there aren't any tables in that database.
Does anyone know a way out of this? I'd much appreciate it.
Lúthien
I've followed the same steps that you have and my findings suggest that the relative path in the New Connection Wizard is relative to NetBeans' working directory which is the directory that NetBeans is installed to.
For example, in your connection string you are "connecting" to a database that resides at <NetBeans-Install-Dir>/ithildin-13-11-11.db. Since this database does not exist, SQLite is creating it for you which is giving you the "illusion" that you are seeing. In my tests, the database that I was trying to connect to with a relative path was created in the NetBeans install directory.
In other words, everything is working as designed.
In your code you can use a relative path and it should be relative to the top of your project's directory. In NetBeans' Databases Service you will need to either use an absolute path to connect to the database that exists (in your project) or you will need to provide a relative path that begins at NetBeans' install directory.
My suggestion is that you use a relative path in your code and an absolute path in the New Connection Wizard.

Proper way to specify database connection string in a DataSet.xsd

I have a Windows CE Form (NETCF 3.5) application that I've created via Visual Studio 2008 (c#) - (However, the core of my question probably applies to normal Windows application, too).
The application implements a SQLite database that I've placed within the project - i.e. The database location is in the sub-directory within my project. So the connection string to the database looks something like:
#"Data Source = C:\src\myApp\data\mydb.s3db"
The connection to the database is fine and works.
After I created the database, I added a Data Set via VS2008's "Data Source Configuration Wizard" (in VS2008, go to Data > Add New Data Source...). The wizard allows us to create a connection to an existing database and, then, choose tables from within that database that will be used in the Data Set that the wizard is about to create.
So the wizard does a fine job of creating the data set which allows us to program against it. The problem that I have is when I deploy the application to my WinCE device.
The problem that I encounter is when the application attempts to access the database when it needs to fill the Data Set with data.
The root of the problem is, the connection string to the database that is defined in the Data Set is per the dev machine - not the local path per the WinCE device.
For example: The connection string in the Data Set is set to
#"Data Source = C:\src\myApp\data\mydb.s3db"
instead of the full path of the target device similar to
#"Data Source = \Program Files\myApp\data\mydb.s3db"
I was able to fix the problem by manually editing the Data Set's .Designer.cs file (at the InitConnection() method). However, it would be nice if VS2008 can manage the connection string for me somehow - i.e. when in dev mode, the connection string points to the database on my dev machine. When in deploy mode, the connection string points to the database on the device.
Is there a way to specify the connection string to point to a relative path rather than the full path, maybe? Or?
Use "|DataDirectory|" in your connection string.
Quote from http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/ ...
|DataDirectory| (enclosed in pipe symbols) is a substitution string that indicates the path to the database. It eliminates the need to hard-code the full path which leads to several problems as the full path to the database could be serialized in different places. DataDirectory also makes it easy to share a project and also to deploy an application.
For example, instead of having the following connection string:
"Data Source= c:\program files\MyApp\Mydb.sdf"
Using DataDirectory, you can have the following connection string:
“Data Source = |DataDirectory|\Mydb.sdf”
To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:
For applications that are put in a folder on the user's computer, the
database folder uses the application folder.
For applications that
are running under ClickOnce, the database folder uses the specific
data folder that is created.

Resources