SQL 您只能在包含的数据库中使用密码创建用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20030612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
You can only create a user with a password in a contained database
提问by Faisal Ashfaq
I am using a contained database, after creating the database I attempted to create a user but I got the error:
我正在使用包含的数据库,在创建数据库后,我尝试创建一个用户,但出现错误:
You can only create a user with a password in a contained database
您只能在包含的数据库中使用密码创建用户
My code is:
我的代码是:
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'contained database authentication', 1
GO
RECONFIGURE WITH OVERRIDE
GO
CREATE DATABASE [MyDb]
CONTAINMENT = PARTIAL
ON PRIMARY
( NAME = N'My', FILENAME = N'C:\My.mdf')
LOG ON
( NAME = N'My_log', FILENAME =N'C:\My_log.ldf')
CREATE USER MyUser
WITH PASSWORD = 'pass@123';
GO
采纳答案by Aleksandr Fedorenko
I think your current database is [master], but you have to use [MyDb]
我认为您当前的数据库是 [master],但您必须使用 [MyDb]
USE [MyDb]
GO
CREATE USER MyUser
WITH PASSWORD = 'pass@123';
GO
回答by buzzard42
In SQL Server 2017, I found that my initial setup did not configure the "contained databases" feature to help this along.
在SQL Server 2017 中,我发现我的初始设置没有配置“包含的数据库”功能来帮助实现这一点。
so, at server level you can check the server properties in the UI or run:
因此,在服务器级别,您可以检查 UI 中的服务器属性或运行:
EXEC sp_configure 'CONTAINED DATABASE AUTHENTICATION'
if the running value isn't 1, then:
如果运行值不是 1,则:
EXEC sp_configure 'CONTAINED DATABASE AUTHENTICATION', 1
GO
RECONFIGURE
GO
At the database level, it also might not have the "contained database" feature fully enabled. The option sits in the Database Properties panel on the Options section, the fourth dropdown at the top...
在数据库级别,它也可能没有完全启用“包含的数据库”功能。该选项位于“选项”部分的“数据库属性”面板中,顶部的第四个下拉菜单...
Containment type == None or Partial
包含类型 == 无或部分
You can set it via SQL too. eg:
您也可以通过 SQL 设置它。例如:
USE [master]
GO
ALTER DATABASE [MyDb] SET CONTAINMENT = PARTIAL
GO
thereafter, you can create the contained user as suggested by @aleksandr
此后,您可以按照@aleksandr 的建议创建包含的用户
USE [MyDb]
GO
CREATE USER MyUser WITH PASSWORD = 'pass@123';
GO
回答by Alpi Murányi
Create the login and the user separately:
分别创建登录名和用户:
CREATE LOGIN MyUser WITH PASSWORD = 'pass@123';
CREATE USER MyUser FOR LOGIN MyUser;
The names can be the same but of course they can also be different.
名称可以相同,但当然也可以不同。