.net连接字符
来源:互联网 发布:如何申请为淘宝达人 编辑:程序博客网 时间:2024/05/16 05:18
c#使用web.config配置中的连接字符串
What other way *is* there to do it?
Here's some pointers on using the Config file for your Connection Strings. It's different in VS2005 than it was in VS2003, but I'll show you both.
For VS2003:
Put the connection string in the appSettings section of the application configuration file (web.config for an app that uses Web Services or for ASP.NET app) and read it with the ConfigurationSettings.AppSettings property, see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpgrfaccessingappsettingssection.asp
Basically, something like this;
<configuration>
<appSettings>
<add key="ConnectionString" value="server=(local);database=MyDataBase;uid=sa;pwd=123" />
</appSettings>
</configuration>
If SQL Server isn't local, then just substitute the Server name for (local).
Get the connection string in your application using the Configuration Settings:
string cConnection = ConfigurationSettings.AppSettings["ConnectionString"];
For VS2005:
It's a little different now for VS2005, but the above stuff will still work (although you'll probably get a compiler warning about ConfigurationSettings.AppSettings being obsolete, but it will still work ok).
Your config file should look like this now:
<configuration>
<connectionStrings>
<add name="ConnectionForMyDatabase" connectionString="server=(local);database=MyDataBase;uid=sa;pwd=123" />
</connectionStrings>
</configuration>
Get the connection string in your application using the new ConfigurationManager:
string cConnection = ConfigurationManager.ConnectionStrings["ConnectionForMyDatabase"].ConnectionString;
- .net连接字符
- ASP.NET与SQL SERVER2005连接密码字符有限制
- ##连接字符
- 字符连接
- 字符连接
- 整理:asp.net连接mysql和sql server的连接字符窜
- asp连接字符
- oracle 字符连接
- 数据连接字符
- 字符的连接
- 用指针连接字符
- 字符的连接
- 字符连接符加号
- 10.连接字符
- StringBuffer类,字符连接
- Asp.NET字符格式化
- ASp.net字符加密
- .Net 转义字符
- mysql与其他数据库不同的地方
- mysql将图片写入数据库
- javascript插入图片
- .net webservices 处理Session
- webservice传来的结果 并放入DataGrid中
- .net连接字符
- 程序员如何缓解压力,保持心理健康
- ArcGIS 9在WIN XP 和 WIN 2003 系统下安装部分动态库不能注册的解决办法
- B/S软件开发测试规范_试行1.1.0604 (收录于网络,供学习用,如果侵犯了你们版权请与本人联系)
- 无限级别分类的类
- 看《数字时代》有感
- 导出Excel是遇到的80070005错误.
- 获取UltraWebGrid选中行的信息
- 从孟良崮战役中读出点启示