.NET 3.5:读取的app.config的ConnectionString? [英] .net 3.5: To read connectionstring from app.config?

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

问题描述

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

平台是.NET 3.5

 < XML版本=1.0编码=UTF-8&GT?;
        <结构>
            <的ConnectionStrings>
                 <新增的connectionString =的providerName =NAME =/>
            < /的ConnectionStrings>
        < /结构>
 

解决方案

请参阅<一href="http://web.archive.org/web/20120307192453/http://davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx"相对=nofollow>阅读Web.Config中和的app.config和企业库DAAB设置连接字符串(在Wayback机器作为原始删除了)

  ConnectionStringSettings连接= ConfigurationManager.ConnectionStrings [MyConnectionString]
字符串的connectionString = connection.ConnectionString
 

您可能需要添加程序集引用 System.Configuration

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

Platform is .net 3.5

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

解决方案

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

You may need to add an assembly reference to System.Configuration

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

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