【发布时间】:2016-07-05 16:50:15
【问题描述】:
到目前为止,我的项目由一个简单的空 asp.net 项目解决方案组成,除了在您启动新项目时 Visual Studio 提供的功能之外,什么都不使用。
我第一次使用迁移来帮助我的开发。到目前为止,我已经很好地启用了迁移,并通过包管理器控制台添加了初始迁移。我所做的唯一更改是修改我的 Web.config 以查看这样的新数据源:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=SYS-VIS-15\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-GiggHub-20160704033906.mdf;Initial Catalog=aspnet-GiggHub-20160704033906;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
现在,当我通过在包管理器控制台中运行“update-database”来更新我的数据库时,我收到以下错误:
文件“C:\Users\Admin\Source\Workspaces\GigHub\GiggHub\GiggHub\App_Data\aspnet-GiggHub-20160704033906.mdf”的目录查找失败,出现操作系统错误 5(拒绝访问。)。 创建数据库失败。无法创建列出的某些文件名。检查相关错误。
我已经检查了我知道的所有权限,但看不到我需要勾选或取消勾选以克服此错误。有谁知道该怎么做?
完整的文件输出如下:
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Data.SqlClient.SqlException (0x80131904): Directory lookup for the file "C:\Users\Admin\Source\Workspaces\GigHub\GiggHub\GiggHub\App_Data\aspnet-GiggHub-20160704033906.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass1a.<CreateDatabaseFromScript>b__19(DbConnection conn)
at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
ClientConnectionId:9b2f396d-dadf-4d0b-a334-1197e86beed1
Error Number:5133,State:1,Class:16
【问题讨论】:
-
您可以使用管理工作室连接到您的数据库吗?
-
提供一些代码来分析,以便我们回答你的问题。
-
你说你只安装了SSMS,是不是说你没有安装数据库引擎?另外,当您说
or on the database时,您是指EF 设计器中的实体模型吗? -
我正在学习这门课程:app.pluralsight.com/library/courses/… 使用 SSMS 我可以很好地连接到我的数据库,但我自己没有在其中创建任何数据库。
-
您说当您尝试更新数据库时遇到错误,您已经在 SSMS 中或仅在 VS 中创建了数据库和表???
标签: c# sql asp.net sql-server