1. The identity of the IIS application pool is set to "Applicationpoolidentify" (more secure)
2. Do not save the database physical file in the physical path of the site, because the IIS application pool is identified as Applicationpoolidentify, and the permissions for the user (application pool name) in the security permissions for the site folder are set to allow only read, for security reasons, Keep this default setting and create a folder in another location to hold the database (for example: D:\LOCALDB\TESTWEBAPP)
3. Right-click the folder where you saved the database files (for example: Testwebapp)----Properties----Security----edit----Add----input name: IIS apppool\ Application pool name----OK----( At this point, only the application pool name will be displayed as the user name in the list of user names----Check Allow permission, modify, read and Execute, List Folder contents, read, write----determine----determine----(complete permission settings on the database folder)
4. Do not use the default instance, create a shared instance yourself, and set the appropriate permissions, the steps are as follows (for example, LocalDB 2012)
4.1 Open cmd, sequentially execute the following three commands in order to create and enable shared instances (SqlLocalDB.exe generally in the "C:\Program Files\Microsoft SQL Server\110\tools\binn" directory)
" InstanceName " "InstanceName" "shareinstancename " " InstanceName "
4.2 Open SQL Server managerment Studio using Windows Authentication Connection (LOCALDB) \.\shareinstancename (note that the data source name format of the shared instance is a bit more than the normal instance)
4.3 Select security----logins----Right-------new logins, on the General tab, using the IIS apppool\ application pool name as the logon name, select Windows Authentication, and on the Server Roles tab, tick the Public "and" sysadmin ", and then create a new login in the same way: NT Authority\System
5. Modify the connection string in the Web. config in the project,
Set "Data Source" to "(LocalDb) \.\shareinstancename",
Set "AttachDbFileName" to "D:\LocalDB\TestWebApp\TestWebApp.mdf"
Other precautions:
* If you restart your system, remember to re-enable the DB instance you created
" InstanceName "
Methods for deploying local database LocalDB on IIS