Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Path in ASP.NET Web.config

Tags:

asp.net

I have the following tag in my ASP.NET Web.config application:

<add name="monitorEntities" connectionString="metadata=res://*/Models.MonitorDB.csdl|res://*/Models.MonitorDB.ssdl|res://*/Models.MonitorDB.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Documents and Settings\jdoe\Desktop\LcdManager\LcdManager\App_Data\monitor.sqlite&quot;'" providerName="System.Data.EntityClient" />

that refers to an EntityFramework instance mapping a sqlite db located in the App_Data directory of the application.

How can i make the link relative so that deploying in a production environment is easier?

Thanks

like image 617
pistacchio Avatar asked Dec 18 '22 06:12

pistacchio


2 Answers

Have you tried

<add name="monitorEntities" connectionString="metadata=res://*/Models.MonitorDB.csdl|res://*/Models.MonitorDB.ssdl|res://*/Models.MonitorDB.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;./App_Data/monitor.sqlite&quot;'" providerName="System.Data.EntityClient" />

or

<add name="monitorEntities" connectionString="metadata=res://*/Models.MonitorDB.csdl|res://*/Models.MonitorDB.ssdl|res://*/Models.MonitorDB.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;|DataDirectory|/monitor.sqlite&quot;'" providerName="System.Data.EntityClient" />
like image 83
David Christiansen Avatar answered Dec 22 '22 00:12

David Christiansen


Can't you use "|DataDirectory|" in the connection string (instead of C:...\App_Data)? E.g:

connectionString="... |DataDirectory|\monitor.sqlite ..."

I know this works for SQL Server Express databases that are deployed in the app_data folder of the application. But I don't know if this works for Entity Framework / SQLite.

like image 33
M4N Avatar answered Dec 22 '22 00:12

M4N