Relative path in ASP.NET Web.config

I have the following tag in an 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" />

which refers to an EntityFramework instance matching sqlite db located in the application's App_Data directory of the application.

How can I make the link relative to simplify deployment in a production environment?

thanks

+3
source share
3 answers

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" />
+5
source

You cannot use "| DataDirectory |" in the connection string (instead of C: ... \ App_Data)? For example:

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.

+6
source

I assume you say this a bit

C:\Documents and Settings\jdoe\Desktop\LcdManager\LcdManager\App_Data\monitor.sqlite

try it

../../App_Data/monitor.sqlite

(not sure about the number "../", but you get the idea ../../App_Data/monitor.sqlite

0
source

Source: https://habr.com/ru/post/1713632/


All Articles