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 configure the database connection string connectionStrings section in ASP.NET web.config

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

Share

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

This article mainly introduces how to configure the database connection string connectionStrings section in ASP.NET web.config. The article is very detailed and has a certain reference value. Interested friends must read it!

In the root directory of the site developed by ASP.NET, there is a file called web.config, which, as the name implies, is configured for the entire site in XML format.

Here we mainly talk about the sections in the document. Section is to configure the string connected to the database, because MS SQL Server and ASP.NET belong to Microsoft products, so the preferred database for ASP.NET development is MS SQL Server. This article only discusses the connection string for MS SQL Server.

In the first case, when developing locally, use the local database, such as the following code

The copy code is as follows:

Discussion:

This is the most common way to use database connection strings for local development using PC. Among them

The name attribute refers to the name of the connection string, which needs to be referenced when you need to use a database in a website; in this case, myConn

The Data Source attribute is the database server. (LocalDB)\ V11.0 indicates that the local database server is used. The version number is 11, that is, SQL Server 2012.

The AttachDbFilename attribute specifies the specific data as the name and location. | DataDirectory | the system directory App_Data in the ASP.NET website. The value of this attribute indicates that you are connected to the Movies.mdf database in this directory, where the mdf file name indicates that the database requires the service of the SQL Server server, but it is an independent database file that can be copied and pasted without the need for database separation in the SQL Server management system (such as SSMS).

Integrated Security=True "description is integrated authentication, which is the way of Windows authentication. As long as there is this attribute and attribute value, the user name and password are not required in the connection string.

ProviderName = "System.Data.SqlClient" is the data provider

This situation is the most commonly used case for local development: you can directly use ASP.NET to create a database (extension is .MDF), or you can use ASP.NET website configuration to generate an ASPNETDB.MDF database. When the database is created, create a connection string in the ASP.NET interface. You only need to provide the name of the connection string. Other properties and attribute values of the connection string can be automatically generated in the web.config file.

In the second case, when developing locally, use the following connection string:

The copy code is as follows:

Note: the connectionString attribute here is simpler than the first case, note the database extension .sdf here, this is the MS SQL Compact version of the database, it does not need to open SQL Server services to use, compact, easy to use, but the support is not as good as .MDF (this is the MS SQL Server standard version of the file format). Therefore, in normal PC development, it is recommended to use .MDF files, if there is no MS SQL Server service running on the machine, .sdf is a good choice.

Third, when developing locally, use the following code:

The copy code is as follows:

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