tailieunhanh - ASP.NET 4 Unleased - p 41
mục App_Data (nếu thư mục chưa tồn tại). Các tập tin sẽ được thêm vào thư mục này. Click OK để tạo ra các thư mục mới. Bạn có thể kết nối đến một cơ sở dữ liệu địa phương tên là bằng cách sử dụng chuỗi kết nối sau đây: | 374 CHAPTER 8 Overview of Data Access When you click Add Visual Web Developer warns you that it needs to create the App_Data folder if the folder doesn t already exist . The file will be added to this folder. Click OK to create the new folder. You can connect to a Local database named by using the following connection string Data Source . SQLEXPRESS AttachDbFilename DataDirectory Integrated Security True User Instance True When you connect to the file the database is attached automatically to Microsoft SQL Server Express. The connection string includes an AttachDbFilename parameter. This parameter represents the physical path to a database file .mdf file . The keyword DataDirectory is used in the path. The DataDirectory keyword represents a website s App_Data folder. Instead of using the DataDirectory keyword you could supply the entire physical path to a database file. The advantage of using the DataDirectory keyword is that you can move your web application easily to a new location without needing to change the connection string. The connection string also includes a User Instance parameter. Creating a User Instance connection enables you to connect to a Local database without using an Administrator account. Because the ASPNET account is not an Administrator account you need to add this parameter to use Local databases from pages. Including the User Instance parameter in a connection string causes a separate user instance of SQL Server to execute with the security context of the user. The first time a user creates a User Instance connection copies of the system databases are copied to a user s application data folder located at the following path C Users Username AppData Local Microsoft Microsoft SQL Server Data SQLEXPRESS A separate set of system databases is created for each user. NOTE By default when a page is served from Internet Information Server the page executes in the security .
đang nạp các trang xem trước