如何使用SQLite/entity框架在app.config中建立数据库的相对路径

Dre*_*eze 5 sqlite app-config relative-path

我希望能够使用相对路径在1个以上的PC上使用SQLite DB.app.config中的connectionstring现在看起来像这样:

<add name="DBPersonEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Users\Dreeze\Documents\Test DB2\DBPerson.s3db&quot;'" providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)

DB文件与应用程序位于同一文件夹中...我想使路径相对,因此它指的是apps文件夹.任何人都可以帮我改变这个连接线吗?

bri*_*lam 0

您应该能够使用数据目录替换字符串:

provider connection string='data source=&quot;|DataDirectory|DBPerson.s3db&quot;'
Run Code Online (Sandbox Code Playgroud)