![](/img/trans.png)
[英]The application built in C# cannot connect to the SQLlite database when it is published
[英]Path to access database with a published C# application
將訪問數據庫發布/安裝到設備后,我需要對訪問數據庫的路徑進行編碼。
在任何設備上安裝訪問數據庫后,如何獲取訪問數據庫的路徑(用於連接字符串)?
有很多方法
Winform Application.StartupPath
.StartupPath
- 返回StartupPath參數(可以在運行應用程序時設置)
System.IO.Directory.GetCurrentDirectory()
- 返回當前目錄,該目錄可能是也可能不是應用程序所在的文件夾。
Environment.CurrentDirectory
。 如果您在DLL文件中使用它,它將返回進程運行的路徑(在ASP.NET中尤其如此)
網頁
ttpContext.Current.Server.MapPath();
- 獲取當前的Web應用程序根目錄
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.