All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用GoLive实现CSS+DIV_[Html教程]
问题“未于信任SQL,Server连接相关联”的解决_[SQL,Server教程]
C#中窗体继承的应用
C#箴言:使用构造函数初始化语句_.net资料_编程技术
C#中GDI+变形的矩阵表示形式
LINQ,in,Action,电子书下载_[Asp.Net教程]
Sql,server动态和静态内存分配_[SQL,Server教程]
SQL中的DDL,DML,DCL语言_mssql学习_编程技术
JS特效:用鼠标事件实现图片的渐显效果_JavaScript技术_编程技术
浅谈.NET中的数据绑定表达式_[Asp.Net教程]
Reading number is top 10 pictures
The Soviet union swimsuit exposure in the 70 year2
影评-疯子,我爱你
战场废物1
The beginning and end
西方气质的东方美女3
美女浴室写真1
传几朵花
China's ambassador to Libya embassy was shock, and the glass is broken in
农夫山泉变身记
新版武松打虎
Download software ranking
c#程序设计案例教程
Twenty piece of palm leaf
Popkart Cracked versions Mobile phone games
matrix3
JSP+Ajax Web development typical examples
Tram sex maniac 2 (H) rar bag3
Boxer Classic video2
尖东毒玫瑰B
星际争霸1.08硬盘免安装版
asp.netWeb服务器高级编程
delv published in(发表于) 2014/1/23 3:14:43 Edit(编辑)
实例:ASP.NET遍历配置文件的连接字符串_[Asp.Net教程]

实例:ASP.NET遍历配置文件的连接字符串_[Asp.Net教程]

实例:ASP.NET遍历配置文件的连接字符串_[Asp.Net教程]

  在ASP.NET 2.0中,提供了更方便的配置文件访问的类,具体可以到 System.Configuration 名称空间下进行查看。本文提供一种在开发过程中常用的得到数据库字符串的方法,为方便使用,写成一个方法进行调用:


  public string GetConnectionString( string _connectionStringsName )
  {
  System.Configuration.ConnectionStringSettingsCollection config = System.Configuration.ConfigurationManager.ConnectionStrings;
  for (int i = 0 ; i < config.Count ; i++)
  {
  if (config[i].Name.Equals(_connectionStringsName, StringComparison.OrdinalIgnoreCase))
  return config[i].ToString();
  }
  return String.Empty;
  }


  如果web.config配置如下:


<connectionStrings>
<add name="ConnectionString1" connectionString="Persist Security Info=False;User ID=sa;Password=;Initial Catalog=DataBase1;Server=(local);" providerName="System.Data.SqlClient"/>
<add name="ConnectionString2" connectionString="Persist Security Info=False;User ID=sa;Password=;Initial Catalog=DataBase2;Server=(local);" providerName="System.Data.SqlClient"/>
</connectionStrings>


  如果写成静态类方法,则可以使用下面的方法进行调用:


string ConnectString = XianhuiMengUtil.GetConnectionString("ConnectionString1");


  另外,如果在遍历时进行输出,则可以看到多出来一个配置项,那是因为machine.config里已经默认定义理一个数据库连接,内容如下:


<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename= DataDirectory aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>


  这就是许多网友在论坛上经常会问:为什么我的程序会调用 SQLEXPRESS 数据库的原因,如果你的数据库配置不正确,或者无法打开时,就会使用 SQLEXPRESS 数据库。







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.