I'm trying to set relative path of database file into my web.config
. I have two projects: DAL (class library), WebApi application. My database store in App_Date
folder in DAL. I want to set the connection string to web.config
of WebApi project.
<add key="connectionString" value="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|Data Directory|\DAL\App_Data\Taskstorage.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
And this is another example:
<add key="connectionString" value="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=~\..\DAL\App_Data\Taskstorage.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
None of them is working. Could you tell me how to fix this problem?
try the following code to read your config file.
using System.Configuration;
string t=ConfigurationManager.AppSettings["connectionString"].ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.