Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t运行';dotnet ef数据库更新';因为没有足够的特权_C#_Sql Server_Docker_Entity Framework Core - Fatal编程技术网

C# Can';t运行';dotnet ef数据库更新';因为没有足够的特权

C# Can';t运行';dotnet ef数据库更新';因为没有足够的特权,c#,sql-server,docker,entity-framework-core,C#,Sql Server,Docker,Entity Framework Core,在开发.NET应用程序和设置数据库方面,我处于令人困惑的停顿状态 我使用的是mssql/sqlexpress的docker容器映像。我已经让它运行,可以登录到系统管理员帐户 我创建了一个登录名CommanderApi、数据库CommanderDb,并使用CommanderApi登录名在该数据库中创建了一个用户。然后我创建了一个初始迁移,当我尝试运行它时,更新失败了 我的方法有问题吗?似乎使用框架和实体背后的设计思想是,它将大量样板SQL代码从程序员手中带走。但是,在我正在观看的教程视频中,他们使

在开发.NET应用程序和设置数据库方面,我处于令人困惑的停顿状态

我使用的是
mssql/sqlexpress
的docker容器映像。我已经让它运行,可以登录到系统管理员帐户

我创建了一个登录名
CommanderApi
、数据库
CommanderDb
,并使用
CommanderApi
登录名在该数据库中创建了一个用户。然后我创建了一个初始迁移,当我尝试运行它时,更新失败了

我的方法有问题吗?似乎使用框架和实体背后的设计思想是,它将大量样板SQL代码从程序员手中带走。但是,在我正在观看的教程视频中,他们使用SSM并执行我上面描述的所有步骤-减去一个步骤-提供用户凭据,我的.NET应用程序的连接字符串将其登录到足够的权限中

当我尝试手动授予
CommanderApi
用户编辑数据库的权限时,我不断收到语法错误:

Changed database context to 'CommanderDb'.  
 1> grant all on CommanderDb to 'CommanderApi'  
 2> go
消息102,15级,状态1,服务器f69fca1fbe0b,第1行
“CommanderApi”附近的语法不正确

消息102,15级,状态1,服务器f69fca1fbe0b,第1行
“CommanderApi”附近的语法不正确

Msg 15151,16级,状态1,服务器f69fca1fbe0b,第1行
找不到对象“CommanderDb”,因为它不存在或您没有权限

消息102,15级,状态1,服务器f69fca1fbe0b,第1行
“CommanderApi”附近的语法不正确

Msg 15151,16级,状态1,服务器f69fca1fbe0b,第1行
找不到对象“CommanderDb”,因为它不存在或您没有权限

Msg 208,16级,状态1,服务器f69fca1fbe0b,第1行
无效的对象名称“CommanderDb”

Msg 343,15级,状态1,服务器f69fca1fbe0b,第1行
CREATE、DROP或ALTER语句中使用了未知的对象类型“CommanderDb”

消息102,15级,状态1,服务器f69fca1fbe0b,第1行
“CommanderDb”附近的语法不正确

消息102,15级,状态1,服务器f69fca1fbe0b,第1行
“CommanderDb”附近的语法不正确

尝试运行dotnet ef数据库更新时出错

C:\Users\Ben\VsCode\.net\angular_template\commander>dotnet ef database update
Build started...
Build succeeded.
失败:Microsoft.EntityFrameworkCore.Database.Command[20102]
执行DbCommand失败(28毫秒)[参数=[],命令类型='Text',命令超时='60']
创建数据库[CommanderDb]
执行DbCommand失败(28毫秒)[参数=[],命令类型='Text',命令超时='60']
创建数据库[CommanderDb]
Microsoft.Data.SqlClient.SqlException(0x80131904):数据库“master”中的创建数据库权限被拒绝

在Microsoft.Data.SqlClient.SqlConnection.OneError(SqlException异常,布尔断开连接,Action
1 wrapCloseInAction)在Microsoft.Data.SqlInternalConnection.OneError(SqlException异常,布尔断开连接,Action
1 wrapCloseInAction)
在Microsoft.Data.SqlClient.TdsParser.ThroweException和Warning(TdsParserStateObject StateObjectObj,布尔调用连接锁,布尔异步关闭)
在Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior、SqlCommand cmdHandler、SqlDataReader dataStream、BulkCopySimpleResultSet bulkCopyHandler、TdsParserStateObject stateObj、Boolean和dataReady)
在Microsoft.Data.SqlClient.SqlCommand.RunExecuteOnQueryTds(字符串方法名、布尔isAsync、Int32超时、布尔asyncWrite)
在Microsoft.Data.SqlClient.SqlCommand.InternalExecuteOnQuery(TaskCompletionSource
1 completion,Boolean sendToPipe,Int32超时,Boolean&usedCache,Boolean asyncWrite,Boolean inRetry,String methodName)的Microsoft.Data.SqlClient.SqlCommand.ExecuteOnQuery()位于Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)的Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection连接,iRelationalDocumentary
2个参数值)
位于Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecutionQuery(IEnumerable`1 migrationCommands,IRelationalConnection连接)
在Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Create()中 位于Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(字符串targetMigration)
位于Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(字符串targetMigration、字符串connectionString、字符串contextType)
在Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(字符串目标迁移、字符串连接字符串、字符串上下文类型)
在Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0()
位于Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(操作)

客户连接ID:d2819228-4d75-47ee-92f4-da88caa6a18f
错误编号:262,状态:1,类别:14
在数据库“master”中创建数据库的权限被拒绝

C:\Users\Ben\VsCode.net\angular\u template\commander>docker exec-it sql server数据库“bash”
mssql@f69fca1fbe0b://$/opt/mssql-tools/bin/sqlcmd-S localhost-U CommanderApi-P Commander9
Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:无法打开用户默认数据库。登录失败..
Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:用户'CommanderApi'登录失败。…
mssql@f69fca1fbe0b://$/opt/mssqltools/bin/sqlcmd-S localhost-U SA-P super\U Duper\U password
Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:用户“SA”登录失败。…
mssql@f69fca1fbe0b://$/opt/mssqltools/bin/sqlcmd-S localhost-U sa-P super\U Duper\U password
Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:用户“sa”登录失败。…
mssql@f69fca1fbe0b://$/opt/mssql工具/bin/sqlc
1> grant all on CommanderDb to CommanderApi
2> go
mssql@f69fca1fbe0b:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P super_DUPER_password
1> grant all on CommanderDb to 'CommanderApi'@'localhost'
2> go
1> grant all on CommanderDb to CommanderApi@localhost
2> go
1> delete CommanderDb
2> go
1> drop CommanderDb
2> go
1> drop 'CommanderDb'
2> go
1> drop database if exists 'CommanderDb'
2> go
1> drop database if exists CommanderDb
2> go
1> exit
C:\Users\Ben\VsCode\.net\angular_template\commander>dotnet ef database update
Build started...
Build succeeded.
version: "3.7"
services:
  sql-server-db:
    container_name: sql-server-db
    image: mcr.microsoft.com/mssql/server:2019-latest
    ports:
      - "1433:1433"
    environment:
      SA_PASSWORD: "super_DUPER_password"
      ACCEPT_EULA: "Y"

services.AddDbContext<CommanderContext>(options => options.UseSqlServer
                (Configuration.GetConnectionString("DefaultConnection")));

"ConnectionStrings" : 
{   
    "DefaultConnection" : "Server=localhost,1433;Initial Catalog=CommanderDb;User ID=CommanderApi;Password=Commander9;"
}