Database connection string explanation, database connection string
Server = (localdb) \ mssqllocaldb; Database = xxxxx; Serve = Server name; Database = Database Name
Server = (localdb) \ mssqllocaldb; AttachDbFilename = xxxx. mdf; Initial Catalog = xxxxx; Serve refers to the Server name; AttachDbFilename refers to the local database file connected to, and Initial Catalog refers to the Database Name
"AttachDbFilename = | DataDirectory | \ data. mdf" "| DataDirectory |" indicates the App_Data folder automatically created in the ASP. NET project and the data. mdb file is created in it.
Integrated security = true
Trusted_Connection = True; Trust connection is used;
MultipleActiveResultSets = true specifies whether to reuse connections of the same users in the database. If this parameter is set to True, when you establish a database connection, the system first queries whether a connection has been established for this user on the server. If yes, the connection is reused. Opening and disabling databases consume system performance. Using this connection method can reduce the burden on the system.
Encrypt = False; Whether to Encrypt;
TrustServerCertificate = True; set to "true" to specify that Microsoft JDBC Driver for SQL Server will not verify the SQL Server SSL certificate. If it is "true", the SQL Server SSL certificate is automatically trusted when the SSL encrypted communication layer is used. If it is "false", Microsoft JDBC Driver for SQL Server verifies the Server SSL certificate. If the server certificate fails to be verified, the driver will cause an error and terminate the connection. The default value is "false ". When and only whenEncryptWhen the attribute is set to "true", this attribute only affects server SSL certificate verification.
AplicationIntent = ReadWrite; indicates the request type sent by the client (ApplicationIntent = ReadOnly)
Generate Database
1. Double-clickStartup. cs
2. Right-click and choose "Open folder"
3. In the controller folder, right-click shift + and choose "Open command window here"
4. Enter cd .. in the Command box and press enter to return to the upper directory.
5. Enter the following command
Dotnet ef migrations add Initial create and initialize database dotnet ef database update database
Dotnet ef migrations add xxxx after updating the Model Field, You need to execute this command to notify vs to re-compile the table and change xxxx to any field name, which is enough for the system to automatically append other fields added to the Change dotnet ef database. update Database
Or in
PM>
Enable-Migrations start migration Configuration
PM> Add-Migration xxxx update database Migration name
After updating the Model Field, You need to execute this command to notify vs to re-compile the table. If xxxx is changed to any field name, the system will automatically append other fields added for the change.
(Note that the data model (class, new item, existing item, etc.) must be added to the Models directory and re-generated. Then, the corresponding controller and view must be added before using this command, use the migration command immediately after it is generatedUpdate-Database: Update the Database.
)
(You can modify and generate a migration command multiple times. You can only update the database once instead of performing multiple migration modifications .)
PM> Update-Database
Update Database