Welcome to Manicprogrammer Sign in | Join | Help

Relative Path + SQLite on ASP.Net = Problem

SQLite is a very nice light-weight embedded database. It's great for testing and it even provides an in-memory database (more on that in another post).

I am using it in a new project of mine. I wanted to have the database file under the web site structure. So all I needed to do was set the connection string to:

Data Source=myDb.db;New=True;UTF8Encoding=True;Version=3;

Right? Wrong!

This path looks for the current directory, which in my case is the solution folder (don't ask!). So I thought: "Well, I'll just use a relative path instead."

Now I got it, right? Wrong!

After a little digging, I found out that this is the path you should use:

Data Source=|DataDirectory|fjords.db;New=True;UTF8Encoding=True;Version=3;

The |DataDirectory| token maps to the App_Data folder in your web application. Finally it works.

Hope this saves some headaches!

#140

Published Monday, May 05, 2008 9:20 AM by heynemann

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Relative Path + SQLite on ASP.Net = Problem

Monday, June 09, 2008 11:49 AM by Peter

You're my hero (for today at least), I just ran into this problem!

# re: Relative Path + SQLite on ASP.Net = Problem

Monday, June 09, 2008 12:32 PM by Bernardo Heynemann

I'm glad it helped you!

Cheers,

Bernardo Heynemann


Enter the text you see in the image:

Leave a Comment

(required) 
required 
(required)