![](/img/trans.png)
[英]Is it possible (and how) to add ConnectionString to app.config at runtime in C#?
[英]How to move connectionString from App.config to code in C#?
我想從 App.config 中刪除 connectionString 並將其添加到代碼中。 我正在使用 WinForms(C#) 和 .Net Framework 4.8。 我的表單上有文本框和數據網格視圖。 我正在使用 Microsoft Access 數據庫 (.mdb)。 我想這樣做是因為數據庫的密碼在 App.config 中可見。 有沒有辦法做到這一點
這是我的 app.config XML 代碼:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Locker.Properties.Settings.pw_dbConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\files\pw_db.mdb;Persist Security Info=True;Jet OLEDB:Database Password=XYZ"
providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
我建議您不要在代碼中定義連接字符串,最好在 app.config 文件中對其進行加密。
請按照以下步驟操作:
如果您在記事本中打開文件,您將看到加密的值,您可以像以前一樣繼續使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.