Code First连接远程数据库,在数据库 'master' 中拒绝了 CREATE DATABASE 权限。
static void Main(string[] args)
{
var builder = new ModelBuilder();
builder.Configurations.Add(new BookConfiguration());
builder.Entity<Person>();
builder.Entity<Publisher>().Property(p => p.Name).IsRequired().HasMaxLength(50);
var model = builder.CreateModel();
Console.Write("Enter an ISBN for the new book: ");
var isbn = Console.ReadLine();
Console.Write("Enter a title for the new book: ");
var title = Console.ReadLine();
// Data access with DbContext
using (var context = new SimpleBookCatalog("CodeFirstWalkthrough", model))
{
var book = new Book
{
ISBN = isbn,
Title = title,
FirstPublished = DateTime.Today,
IsFiction = false,
Author = new Author { FirstName = "Rowan", LastName = "Miller" },
Publisher = new Publisher { Name = "EF Books" }
};
context.Books.Add(book); //报错:在数据库 'master' 中拒绝了 CREATE DATABASE 权限。
context.SaveChanges();
}
}
数据库连接配置:
<add name="MyConnection"
providerName="System.Data.SqlClient"
connectionString="data Source=192.168.253.31\SQLEXPRESS; initial catalog=CodeFirstWalkthrough;User ID=sa;Password=uf_1234;Persist Security Info=True;User Instance=True" />