web.config文件中的连接字符串 [英] connection string in web.config file

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

问题描述

在web.config文件中放入连接字符串后我必须在page.aspx.cs页面编写什么编码?

after putting connection string in web.config file what coding i have to do in page.aspx.cs page?

推荐答案

string connection_string = ConfigurationManager.ConnectionStrings [ 你的conn字符串名称] .ConnectionString;





在页面后面的代码中使用它来建立连接到数据库
string connection_string = ConfigurationManager.ConnectionStrings["Your conn string name"].ConnectionString;


use this in code behind page to establish the connection..to database


我假设您要从aspx页面中的web.config文件中检索连接字符串值。如果是这种情况,请看下面的链接,例如

如何:从Web.config文件中读取连接字符串 [ ^ ]

在web.config中存储连接字符串 [ ^ ]



更多示例此处 [ ^ ]
I assume you want to retrieve the connection string value from web.config file in your aspx page. If that''s the case take a look at the below links for example
How to: Read Connection Strings from the Web.config File[^]
Store connection string in web.config[^]

More examples here[^]


System.Configuration.ConfigurationManager.
    ConnectionStrings["connectionStringName"].ConnectionString;



为此,添加引用System.Configuration



http://msdn.microsoft.com/en-us/library/ms178411(v=vs.100).aspx [ ^ ]





希望这些有帮助......


For this, add reference System.Configuration

http://msdn.microsoft.com/en-us/library/ms178411(v=vs.100).aspx[^]


Hope these helps...


这篇关于web.config文件中的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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