.net 3.5:从 app.config 读取连接字符串? [英] .net 3.5: To read connectionstring from app.config?

查看:34
本文介绍了.net 3.5:从 app.config 读取连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 .net api 从 app.config 文件中读取连接字符串信息?

How to read connection string info from app.config file using .net api?

平台是.net 3.5

Platform is .net 3.5

     <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
            <connectionStrings>
                 <add connectionString="" providerName="" name=""/>
            </connectionStrings>
        </configuration> 

推荐答案

请参阅 读取 Web.Config 和 App.Config 以及企业库 DAAB 设置中的连接字符串(在 Wayback 机器上,因为原始文件已被删除)

Please see Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings (on the Wayback Machine as the original got deleted)

ConnectionStringSettings connection = ConfigurationManager.ConnectionStrings["MyConnectionString"]
string connectionString = connection.ConnectionString

您可能需要添加对 System.Configuration

这篇关于.net 3.5:从 app.config 读取连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆