ASP.NET MVC 发布到虚拟空间碰到了问题!在数据库 'master' 中拒绝了 CREATE DATABASE 权限。

「已注销」 2015-07-13 12:15:10
在数据库 'master' 中拒绝了 CREATE DATABASE 权限。
怎么破?
求教!
我知道虚拟空间肯定不能创建 数据库的,肯定是用已有的,我想问 下怎么才能用EF连接已有的数据库而不让其自行创建数据库谢谢!


...全文
205 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2015-07-13
  • 打赏
  • 举报
回复
引用 1 楼 findcaiyzh 的回复:
你在web.config中指定连接字符串(指向已经存在的数据库),code first就不会新建数据库了。 参考 http://weblogs.asp.net/scottgu/using-ef-code-first-with-an-existing-database Importantly, though, the auto-create database option is just an option – it is definitely not required. If you point your connection-string at an existing database then EF “code first” will not try and create one automatically. The auto-recreate option also won’t be enabled unless you explicitly want EF to do this – so you don’t need to worry about it dropping and recreating your database unless you’ve explicitly indicated you want it to do so. For this blog post we will not auto-create the database. Instead, we’ll point at the existing Northwind database we already have. To do this we’ll add a “Northwind” connection-string to our web.config file like so:

connectionStrings>
      
    <add name="Northwind" 
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\northwind.mdf;User Instance=true" 
         providerName="System.Data.SqlClient" />
 
  </connectionStrings>
注意 链接字符串的name要匹配 你初始化DBContext时的名字,例如下面代码中的name=那个部分。

public class MyApplicationContext: DbContext
{
    public MyApplicationContext() : base("name=ConnectionStringName") { }

    public DbSet<Customer> Customers { get; set; }
}
好的,谢谢 ,我回去试试
Justin-Liu 2015-07-13
  • 打赏
  • 举报
回复
不用code first 连接现有数据库
  • 打赏
  • 举报
回复
现在的数据库连接字符串都不指定数据库的?
宝_爸 2015-07-13
  • 打赏
  • 举报
回复
你在web.config中指定连接字符串(指向已经存在的数据库),code first就不会新建数据库了。 参考 http://weblogs.asp.net/scottgu/using-ef-code-first-with-an-existing-database Importantly, though, the auto-create database option is just an option – it is definitely not required. If you point your connection-string at an existing database then EF “code first” will not try and create one automatically. The auto-recreate option also won’t be enabled unless you explicitly want EF to do this – so you don’t need to worry about it dropping and recreating your database unless you’ve explicitly indicated you want it to do so. For this blog post we will not auto-create the database. Instead, we’ll point at the existing Northwind database we already have. To do this we’ll add a “Northwind” connection-string to our web.config file like so:

connectionStrings>
      
    <add name="Northwind" 
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\northwind.mdf;User Instance=true" 
         providerName="System.Data.SqlClient" />
 
  </connectionStrings>
注意 链接字符串的name要匹配 你初始化DBContext时的名字,例如下面代码中的name=那个部分。

public class MyApplicationContext: DbContext
{
    public MyApplicationContext() : base("name=ConnectionStringName") { }

    public DbSet<Customer> Customers { get; set; }
}
This book begins with you working along as Scott Guthrie builds a complete ASP.NET MVC reference application. He begins NerdDinner by using the File-New Project menu command within Visual Studio to create a new ASP.NET MVC Application. You'll then incrementally add functionality and features. Along the way you'll cover how to create a database, build a model layer with business rule validations, implement listing/details data browsing, provide CRUD (Create, Update, Delete) data form entry support, implement efficient data paging, reuse UI using master pages and partials, secure the application using authentication and authorization, use AJAX to deliver dynamic updates and interactive map support, and implement automated unit testing. From there, the bulk of the rest of the book begins with the basic concepts around the model view controller pattern, including the little history and the state of the MVC on the web today. We'll then go into the ways that MVC is different from ASP.NET Web Forms. We'll explore the structure of a standard MVC application and see what you get out of the box. Next we dig deep into routing and see the role URLs play in your application. We'll deep dive into controllers and views and see what role the Ajax plays in your applications. The last third of the book focuses entirely on advanced techniques and extending the framework. In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for. It's worth noting, that ASP.NET MVC is not a replacement for ASP.NET Web Forms (aka just "ASP.NET"). Many web developers have been giving a lot of attention to other web frameworks out there (Ruby on Rails, Django) which have embraced the MVC (Model-View-Controller) application pattern, and if you're one of those developers, or even if you're just curious, this book is for you. MVC allows for (buzzword alert ) a "greater separation of concerns" between components in your application. The book goes into the ramifications of this, but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript, as well as complete control over the programmatic flow of your application.
This book begins with you working along as Scott Guthrie builds a complete ASP.NET MVC reference application. He begins NerdDinner by using the File-New Project menu command within Visual Studio to create a new ASP.NET MVC Application. You'll then incrementally add functionality and features. Along the way you'll cover how to create a database, build a model layer with business rule validations, implement listing/details data browsing, provide CRUD (Create, Update, Delete) data form entry support, implement efficient data paging, reuse UI using master pages and partials, secure the application using authentication and authorization, use AJAX to deliver dynamic updates and interactive map support, and implement automated unit testing. From there, the bulk of the rest of the book begins with the basic concepts around the model view controller pattern, including the little history and the state of the MVC on the web today. We'll then go into the ways that MVC is different from ASP.NET Web Forms. We'll explore the structure of a standard MVC application and see what you get out of the box. Next we dig deep into routing and see the role URLs play in your application. We'll deep dive into controllers and views and see what role the Ajax plays in your applications. The last third of the book focuses entirely on advanced techniques and extending the framework. In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for. It's worth noting, that ASP.NET MVC is not a replacement for ASP.NET Web Forms (aka just "ASP.NET"). Many web developers have been giving a lot of attention to other web frameworks out there (Ruby on Rails, Django) which have embraced the MVC (Model-View-Controller) application pattern, and if you're one of those developers, or even if you're just curious, this book is for you. MVC allows for (buzzword alert ) a "greater separation of concerns" between components in your application. The book goes into the ramifications of this, but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript, as well as complete control over the programmatic flow of your application.
This book begins with you working along as Scott Guthrie builds a complete ASP.NET MVC reference application. He begins NerdDinner by using the File-New Project menu command within Visual Studio to create a new ASP.NET MVC Application. You'll then incrementally add functionality and features. Along the way you'll cover how to create a database, build a model layer with business rule validations, implement listing/details data browsing, provide CRUD (Create, Update, Delete) data form entry support, implement efficient data paging, reuse UI using master pages and partials, secure the application using authentication and authorization, use AJAX to deliver dynamic updates and interactive map support, and implement automated unit testing. From there, the bulk of the rest of the book begins with the basic concepts around the model view controller pattern, including the little history and the state of the MVC on the web today. We'll then go into the ways that MVC is different from ASP.NET Web Forms. We'll explore the structure of a standard MVC application and see what you get out of the box. Next we dig deep into routing and see the role URLs play in your application. We'll deep dive into controllers and views and see what role the Ajax plays in your applications. The last third of the book focuses entirely on advanced techniques and extending the framework. In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for. It's worth noting, that ASP.NET MVC is not a replacement for ASP.NET Web Forms (aka just "ASP.NET"). Many web developers have been giving a lot of attention to other web frameworks out there (Ruby on Rails, Django) which have embraced the MVC (Model-View-Controller) application pattern, and if you're one of those developers, or even if you're just curious, this book is for you. MVC allows for (buzzword alert ) a "greater separation of concerns" between components in your application. The book goes into the ramifications of this, but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript, as well as complete control over the programmatic flow of your application.
This book begins with you working along as Scott Guthrie builds a complete ASP.NET MVC reference application. He begins NerdDinner by using the File-New Project menu command within Visual Studio to create a new ASP.NET MVC Application. You'll then incrementally add functionality and features. Along the way you'll cover how to create a database, build a model layer with business rule validations, implement listing/details data browsing, provide CRUD (Create, Update, Delete) data form entry support, implement efficient data paging, reuse UI using master pages and partials, secure the application using authentication and authorization, use AJAX to deliver dynamic updates and interactive map support, and implement automated unit testing. From there, the bulk of the rest of the book begins with the basic concepts around the model view controller pattern, including the little history and the state of the MVC on the web today. We'll then go into the ways that MVC is different from ASP.NET Web Forms. We'll explore the structure of a standard MVC application and see what you get out of the box. Next we dig deep into routing and see the role URLs play in your application. We'll deep dive into controllers and views and see what role the Ajax plays in your applications. The last third of the book focuses entirely on advanced techniques and extending the framework. In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for. It's worth noting, that ASP.NET MVC is not a replacement for ASP.NET Web Forms (aka just "ASP.NET"). Many web developers have been giving a lot of attention to other web frameworks out there (Ruby on Rails, Django) which have embraced the MVC (Model-View-Controller) application pattern, and if you're one of those developers, or even if you're just curious, this book is for you. MVC allows for (buzzword alert ) a "greater separation of concerns" between components in your application. The book goes into the ramifications of this, but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript, as well as complete control over the programmatic flow of your application.
This book begins with you working along as Scott Guthrie builds a complete ASP.NET MVC reference application. He begins NerdDinner by using the File-New Project menu command within Visual Studio to create a new ASP.NET MVC Application. You'll then incrementally add functionality and features. Along the way you'll cover how to create a database, build a model layer with business rule validations, implement listing/details data browsing, provide CRUD (Create, Update, Delete) data form entry support, implement efficient data paging, reuse UI using master pages and partials, secure the application using authentication and authorization, use AJAX to deliver dynamic updates and interactive map support, and implement automated unit testing. From there, the bulk of the rest of the book begins with the basic concepts around the model view controller pattern, including the little history and the state of the MVC on the web today. We'll then go into the ways that MVC is different from ASP.NET Web Forms. We'll explore the structure of a standard MVC application and see what you get out of the box. Next we dig deep into routing and see the role URLs play in your application. We'll deep dive into controllers and views and see what role the Ajax plays in your applications. The last third of the book focuses entirely on advanced techniques and extending the framework. In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for. It's worth noting, that ASP.NET MVC is not a replacement for ASP.NET Web Forms (aka just "ASP.NET"). Many web developers have been giving a lot of attention to other web frameworks out there (Ruby on Rails, Django) which have embraced the MVC (Model-View-Controller) application pattern, and if you're one of those developers, or even if you're just curious, this book is for you. MVC allows for (buzzword alert ) a "greater separation of concerns" between components in your application. The book goes into the ramifications of this, but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript, as well as complete control over the programmatic flow of your application.

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧