Copy codeThe Code is as follows:
Public partial class CMS_DBDataContext
{
Partial void OnCreated ()
{
// Create a database if the database does not exist
If (! This. DatabaseExists ())
{
This. CreateDatabase ();
}
}
}
The following error occurs: the create database permission is denied in the 'master' DATABASE.
After reading the relevant information, we know that to run the SQL Server database, you must create a database under the instance. Whether it is directly created, appended, or restored, you must create a database under the instance.
Therefore, modify the connection string,
<Add name = "SE_DBConnectionString" connectionString = "Data Source =. \ sqlexpress; Initial Catalog = SE_DB; Integrated Security = True; Pooling = False; User Instance = True "providerName =" System. data. sqlClient "/>
After adding User Instance = True, you can use the Instance to successfully create a database.
Solution 2:
Assign the database administrator role to the user who logs on to the database. This error can also be solved. For example, in ASP. NET, a network service user accesses the database and can set the database role of this user as the database administrator. In short, ensure that the login user has the right to create, modify or delete the database.