in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Connection string with relative paths

Last post 06-21-2007 2:33 PM by Robert Simpson. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-21-2007 1:27 PM

    Connection string with relative paths

        Hi,

    I'm using the .NET 2.0 <connectionString> directives:

    <connectionStrings>
     <add name="core" connectionString="Data Source=core.db"/>
     <add name="delicious" connectionString="Data Source=delicious.db"/>
    </connectionStrings>

    This is all very nice, but this does not seem to map to a path relative to the web root /
    For example, I have all my databases (yes I use more than one) in /data/.

    In order to get it working it seems I have to specify the full path on the server,
    for example "Data Source=f:/wwwroot/mysite/data/core.db"
    (or "Data Source=/srv/www/mysite/data/core.db" on linux).

    Instead I would like it so that it doesn't matter where the website is fysically located on the server.
    Normally I'd use Server.MapPath but I can't use that because
    1) Server.MapPath(SQLiteConnection dbConnection = new SQLiteConnection(ConfigurationManager.ConnectionStrings["core"].ConnectionString));
    wouldn't do me any good.
    2) I'm not accessing the database from an ASP.NET page, but from a business object in the App_Code directory and Server.MapPath is (by default) not available there.

    How do I solve this?
    Thank you.


  • 06-21-2007 2:33 PM In reply to

    Re: Connection string with relative paths

    Use the |DataDirectory| token in the string and the program will look in your App_Data directory for the file in ASP.NET

    <connectionStrings>
     <add name="core" connectionString="Data Source=|DataDirectory|core.db"/>
     <add name="delicious" connectionString="Data Source=|DataDirectory|delicious.db"/>
    </connectionStrings>

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems