Using SQLite for Simple Database Storage - The Last Step
(Page 6 of 6 )
The last step which I haven't shown is the connection to the database. Like other providers a connection string is necessary. Because the database is disk based rather than server based, the connection string is very different. The following command connected to the database in my sample application:
conn = New SQLiteConnection("Data Source=c:\accounts\user.db;Version=3")
conn.Open()
This is pretty much the minimal connection string necessary. Using an absolute path to the database is mandatory. When I tried to refer to a file in the application folder as a local file, the provider attempted to look for it in my systems folder. Likewise, if I excluded the version parameter the provider made random and inaccurate guesses as to the version of the database I was using. Make sure to match this version number to the major version number of the client you use to create the database.
Using SQLite on Windows requires slightly more administrative skill than on other platforms. During a transaction (such as an Insert or Update), the database changes are stored in a journal file until the entire transaction can be completed and written to the database. The web server process will need write access to the file, and permission to create files in the database directory. This permissions management can't be easily accomplished via an FTP connection, so you'll need console or remote desktop access to your web server. Keep this in mind if you're considering using SQLite in a hosted application environment.
Getting SQLite
SQLite is down-loadable from http://www.sqlite.org. The ADO.NET data provider I used can be downloaded from http://sourceforge.net/projects/adodotnetsqlite/. Other providers are available, including COM objects which can be used from traditional ASP pages.
If your interest lies instead with desktop applications, SQLite is very easy to deploy. For Windows applications the engine is encapsulated in a DLL which must be distributed with your program. No special configuration is needed to give access to the SQLite databases, so even including the library in a ZIP file with your executable will be sufficient for distribution.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |