首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Code First连接远程数据库,在数据库 'master' 中拒绝了 CREATE DATABASE 权限。该怎么解决

2012-06-15 
Code First连接远程数据库,在数据库 master 中拒绝了 CREATE DATABASE 权限。[codeC#][/code]static voi

Code First连接远程数据库,在数据库 'master' 中拒绝了 CREATE DATABASE 权限。
[code=C#][/code]
  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" />

创建数据库不成功,在master中拒绝create,不知道怎么解决啊,唉!


[解决办法]

XML code
<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" /> 

热点排行