Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make different settings for ASP.NET1.1 and ASP.NET2.0 database connection strings

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to set different connection strings between ASP.NET1.1 and ASP.NET2.0 database? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a simpler and easier way.

In the asp.net1.1 era, database connection strings were written under the appSettings section of the web.config file. The specific words are as follows:

< configuration>

< appSettings>

< add key="ConnString" value="Server=(local);Database=pubs;User Id=sa;Password=sa;"/>

< /appSettings>

Of course, in the appsetings section, you can store not only database connection strings, but also some custom configurations related to the program.

information。 When in use, you should first using System.Configuration; and then string strConn=Configuration.AppSettings ["ConnString"].

From the ASP.NET1.1 era to the asp.net2.0 era, not only the appSettings segment is retained, but also a new connectionStrings segment is added. Generally, the database connection string used in the program is placed under this section, and other custom configuration information is placed under the appSettings section. At the same time, Microsoft does not recommend using the Configuration class, but the ConfigurationManager class. To use it, add the following under the connectionStrings section:

< add name="ConnString" connectionString="Server=(local);Database=pubs;User Id=sa;Password=sa;" providerName="System.Data.SqlClient"/>

In use, using System.Configuration; is still used first, but it must be noted that references must be added in the project, System.Configuration must be found in the pop-up dialog box, and click to add, otherwise, the ConfigurationManager class cannot be used.

Finished this part, is how to get the database connection string, here we generally use the following methods to get the connection string.

String strConn=ConfigurationManager.ConnectionStrings ["ConnString"] .ToString ()

Of course, indexes starting from 0 can also be used in square brackets, but it should be noted that the configuration in web.config in asp.net2.0 is inherited from machine.config in the machine, and there is a database connection string pointing to SQL2005 Express by default in the machine.config file, so when you directly use ConfigurationManager.ConnectionStrings [0] .ToString () Instead of the database connection string you wrote in web.config, you get the database connection string that points to SQL2005 Express. I got stuck in this place for a while, and then I used breakpoint debugging to find this problem, so it's better to use the name of the connection string directly, and there will be no problem.

This is the answer to the question about how to set up ASP.NET1.1 and ASP.NET2.0 database connection strings. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report