从C#中的app.config获取数据 [英] Getting data from app.config in C#
本文介绍了从C#中的app.config获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计们
这是我的app.config:
hi guys
this is my app.config :
<connectionStrings>
<add name="database_1"
connectionString="Provider=OraOLEDB.Oracle;Data Source= (DESCRIPTION=(HOST=000.00.00.00.0 )(PORT=00000))) (CONNECT_DATA = ;User Id=username;Password=password"/>
</connectionString>
我如何获得用户名和密码的值?注意:我有几个数据库。
我尝试了什么:
i试图从这里访问它:
how can i get the value of username and password ? NOTE: i have several databases.
What I have tried:
i tried to access it from here :
System.Configuration.ConfigurationSettings.ConnectionStrings
但未能这样做。
有人可以帮忙吗?
but failed to do so.
someone can help please?
推荐答案
string cnnString = System.Configuration.ConfigurationManager.ConnectionStrings [database_1] .ConnectionString;
string cnnString = System.Configuration.ConfigurationManager.ConnectionStrings["database_1"].ConnectionString;
我googledc#从连接字符串中提取用户名和密码这是第一个结果
c# - 从连接字符串获取用户名和密码的正确方法? - 堆栈溢出 [ ^ ]
I googled "c# extract username and password from connection string" and this was the first result
c# - Right way to get username and password from connection string? - Stack Overflow[^]
这篇关于从C#中的app.config获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文