如何从此代码中检索连接字符串 [英] how the connectionstring is retrieve from this code
本文介绍了如何从此代码中检索连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想知道如何从此代码中检索连接字符串
Hi
I want to know how the connectionstring is retrieved from this code
Application[Constants.appSettingsDataFolderPath] = ConfigurationManager.AppSettings[Constants.appSettingsDataFolderPath]
谢谢
Akila
Thanks
Akila
推荐答案
如果您使用.net 2.0,则只能在< appsettings>中声明连接字符串.在web.config中.
但是如果您使用.net 3.5,则可以直接在< connectionstring>中指定connectionstring. webconfig中的标签.
-------------------------------------------------- -------------------------------
在.NET 3.5中:
if you use .net 2.0 you can only declare connectionstring within <appsettings> in web.config.
but if you use .net 3.5 means you can directly specify connectionstring within <connectionstring> tags in webconfig.
---------------------------------------------------------------------------------
in .NET 3.5:
<connectionstrings>
<add>
name="ConnectionStringname";
connectionString="Data Source=serverName;Initial
Catalog=yourdb;Persist Security Info=True;User
ID=userName;Password=password";>
</add></connectionstrings>
您可以使用
在程序中调用它
you can call it in program by using,
string connStr = ConfigurationManager.ConnectionStrings["ConnectionStringname"].ConnectionString;
-------------------------------------------------- ---------------------------------
在.NET 2.0中:
-----------------------------------------------------------------------------------
in .NET 2.0:
<appsettings>
<add key="ConnectionInfo" value="server=(local);database=yourdb;Integrated Security=SSPI">
</add></appsettings>
您可以使用
在程序中调用它
you can call it in program by using,
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
使用F10在此处放置调试点跟踪将值放置在快速监视窗口中
Put a debug point here trace using F10 put the value in quick watch window
您好,
您使用配置管理器类检索您在Appsettings部分的Web.config或app.config中编写的连接字符串.
谢谢,
K.Vigneshwar.
Hi,
The Connection String which you wrote in the Web.config or app.config in the Appsettings section is retrieved using Configuration Manager Class.
Thanks,
K.Vigneshwar.
这篇关于如何从此代码中检索连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文