Asp. NET in the use of VWD operations database

Source: Internet
Author: User
Tags log connect sql server express

This article describes the File-based database approach in Visual Studio 2005 and how designers build and use these databases, including visual Web Developer and data, local and server databases, building local databases, binding to local databases, Deploy the local database.

VWD2005 contains SQL Server, the Edition Express, which is a free version of SQL Server 2005, and is intended for unprofessional or fanatical developers who want to build applications with simple database solutions. Because SQL Server Express supports a complete SQL Server programming model, such as SQLCLR, T-SQL, stored procedures, views, triggers, and XML data types, you can use SQL Server Express to understand these technologies, And make sure your applications can run on a higher level platform (for example, SQL Server Enterprise Edition). SQL Server Express is easy to download and install (it is less than 36MB) and is included in Visual Studio 2005 and Visual Web Developer 2005.

Visual Studio includes tools for database management, such as Database Explorer and Query Builder, which you can use to manage the SQL Server Express Database (Builder). Visual Studio also supports a new file-based database for building a SQL Server Express database and as part of a project. At the same time, Visual Studio 2005 and SQL Server, the full Express offer a complete solution for building and deploying data-driven Web applications, including some of the following features:

Database project Data Items

Local Database connection

Database Browser Management

Relative path Connection string

xcopy Deployment support

Integrated debugging support

This article describes the File-based database approach in Visual Studio 2005 and how designers build and use these databases.

Visual Web Developer and data

The Visual Web Developer provides a number of tools for Web applications to use databases. You can use a database browser to easily connect to a database and create or view a database diagram or outline (schema). You can also use the Query Builder dialog box and the query results table to query the database and populate the data. Creating a new database (using local files) is also provided as a project data item.

Once you have connected the database in the Visual Web developer, you can drag and drop the database table onto the page to establish the data-bound GridView control. The Visual Web developer automatically establishes an associated data source control and configures its selection, update, insert, and delete operations based on the data table. This quick action saves you a lot of work to manually build a data source, and you can easily replace the GridView with the appropriate data-bound controls as needed.

Local and server databases

You may already be familiar with server-based databases and connection strings. In this case, the database server (for example, SQL Server 2005) associates the database name with the database files maintained by the server. You can connect to a server-based database by specifying the server name, database name, and credentials, for example:

"server=(local)\SQLExpress;database=Pubs;Integrated Security=true"

However, Visual Studio 2005 also supports the concept of a local database, which is a file added to the App_Data directory of the current Web application. It is safe to store data files in the App_Data directory because the content in this directory will never respond to user requests. This directory is also the recommended location for storing XML files and other data stores. The local SQL Server Express database has a. MDF extension (for example, "Mydatabase.mdf"), which is the standard file format supported by SQL Server. When connecting to the server, the database also has an associated log file (for example, "Mydatabase_log."). LDF "). The location of the database files and log files must be together.

We can automatically attach the local file database to SQL Server Express by using the relative path connection string. A relative path ensures that the database connection is not interrupted when the application migrates to any other place. The relative path connection string in the Web application looks like this:

"server=(local)\SQLExpress;AttachDbFileName=|DataDirectory|
MyDatabase.mdf;Integrated Security=true;User Instance=true"

The connection string above also has two additional attributes. The AttachDbFileName property specifies the location of the database file that is dynamically attached to the server when the connection is opened. Although this property can accept the full path of the database (for example, use | datadirectory| syntax), but at run time this path is replaced by the application's App_Data directory. This also ensures that the connection is not interrupted when the application migrates to another location. The second property is the user instance=true, which specifies how SQL Server Express attaches the database. In this case, SQL Server Express creates a new process for attaching the database to a new instance, running under the identity of the user who opened the connection. In a asp.net application, this user is the local ASPNET account or the default network Service, which relies on the operating system. In order to securely attach a database file provided by a non-system administrator account (such as a asp.net account), it is necessary to establish a separate SQL Server user instance.

Note that because all ASP.net applications run under the same process by default, all applications attach the local database to the same SQL Server Express instance. This means that regardless of which database the application initially attaches, all applications have the same access rights to all databases attached to the instance. To isolate different applications, you must have each application run in a different worker process or application pool (in IIS 6). For this reason, the local SQL Server database is intended primarily for easy development rather than a server-based database in lieu of a shared host environment.

Another important point is that two users are not allowed to connect to a local database at the same time. When designing an application in Visual Studio, the designer automatically frees the connection to ensure that Visual Studio and asp.net can share database files, such as debugging running applications in the designer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.