How to get the "connection string" from web.config file
2008-08-28 23:58
507 查看
The connection strings stored in web.confing for asp.net2.0 are different from that in asp.net 1.0
The connectionstring is stored in the <appSettings> for ASP.net1.0 whereas it is in the <connectionStrings> section for ASP.net2.0
<appSettings>
<!-- Database connection string -->
<add key="ConnStr" value="Data Source=(local);database=SCardDB;UID=sa;Password=;Persist Security Info=True;"/>
</appSettings>
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=myDBServer;database=myDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
I know how to get the connectionstring from web.config of asp.net1.0.
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
How to get it from web.config of asp.net2.0?
string strConnString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
The connectionstring is stored in the <appSettings> for ASP.net1.0 whereas it is in the <connectionStrings> section for ASP.net2.0
<appSettings>
<!-- Database connection string -->
<add key="ConnStr" value="Data Source=(local);database=SCardDB;UID=sa;Password=;Persist Security Info=True;"/>
</appSettings>
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=myDBServer;database=myDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
I know how to get the connectionstring from web.config of asp.net1.0.
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
How to get it from web.config of asp.net2.0?
string strConnString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
相关文章推荐
- How to get the content of the 'identity' section in web.config
- Unable to get the project file from the Web Server(in .NET 2005 IDE)
- How to Modify the web.config file in SharePoint using SPWebConfigModification?
- 解决unable to get the project file from the web server
- How to Get Help With a Command from the Linux Terminal
- [Drupal] How to change the admin url from /admin to /config in Drupal 6.x
- How to get file extension from string in C++
- how to get charset from string and file
- How to get a notification from Linux when the set of network interfaces changes
- How to check the java compiler version from a java class file?
- From the Wallet to the Web, Java Cards Get Pervasive @ JDJ
- Unable to get the project from the web server. 错误的解决方法
- How To Get Application Path,And How To Get The Path's Directory,File Name,And Type Info(如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息)
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- Unable to get the project ile from the web server的解决方法
- How can i specify the resource to get from R.res.drawable dynamically?
- This tip shows how to extract the width and height from a bitmap source file on disk.
- how to get the default maximum heap size for Sun's JVM from Java SE 6 or 7
- How to get parameters from the URL?
- How to get the size of file in C++ - 在C++中如何获取文件的大小