zoukankan      html  css  js  c++  java
  • appSettings与connectionStrings


    在web.config中有很多设置,具体的偶也不知道,但今天碰到一个解决了的,小小经验,仅供初学者。
    在设置数据库连接时,我们喜欢把连接字符串放到web.config中,这样非常方便改动。其中,我学习到了两种方式:1.在asp.net的配置中的应用程序配置中,创建应用程序,名称为”ConnectionString“(你的连接字符串),值为”server=(local);uid=sa;pwd=;database=Tmp“(你的连接设置)。
       2.在web.config中添加<connectionStrings>
      <add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=Tmp;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    这两种方法的区别偶还没弄太明白,但二者的使用有一定的区别。
    对于1:引用的方式应该为,string conn = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
    对于2:引用的方式应该为,string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();  并且必须using System.Web.Configuration;
    就这么多,以后如果有什么问题,我会继续改进。
  • 相关阅读:
    ubuntu下安装VMware tools
    ubuntu 输入su提示认证失败的解决方法
    Squishy Bird 压扁小鸟
    js 毫秒转日期(yy-MM-dd hh:mm:ss)
    js--使用构造器函数来新建对象及操作
    css中table样式
    js 字符串截取
    JavaScript中Math--random()/floor()/round()/ceil()
    canvas draw a image
    html5 canvas simple drawing
  • 原文地址:https://www.cnblogs.com/kulong995/p/1270600.html
Copyright © 2011-2022 走看看