一、問題
使用ef codefirst開發,無法創建數據庫的問題,如下提示
Server Error in '/' Application. 在多語句事務內不允許使用 CREATE DATABASE 語句。 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: 在多語句事務內不允許使用 CREATE DATABASE 語句。 Source Error: Line 32: */ Line 33: public ZmBlogDbContext(string nameOrConnectionString) Line 34: : base(nameOrConnectionString) Line 35: { Line 36:
二、解決方法
這是 EF 拋出的異常,只要先創建好數據庫就可以了
create database [ZmBlog]
提示:
這個錯誤是在第一次運行abp出現的,創建數據庫后,這時要使用 update-database 進行數據遷移,否則基礎數據是空的
解決方案二:
1、創建ABP空模板后,按F5,生成報:在多語句事務內不允許使用 CREATE DATABASE 語句錯誤
解決辦法:打開Nugut程序包管理器控制台,默認項目選擇:EntityFramework;輸入:Update-Database -Verbose
2、如果出現:Cannot determine a valid start-up project. Using project 'MyPro.EntityFramework' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
解決辦法:Update-Database -StartUpProjectName "MyPro.Web"
通過StartUpProjectName指定啟動項目