我有SQL Server 2005,我尝试用用户创建一个新数据库。
我在master db上使用了这些命令:
CREATE LOGIN mobstat WITH PASSWORD = 'mobstat123';
CREATE USER mobstat FOR LOGIN mobstat;
CREATE SCHEMA mobstat AUTHORIZATION mobstat;
CREATE DATABASE mobstat COLLATE SQL_Hungarian_CP1250_CI_AS;
EXEC sp_addrolemember N'db_owner', N'mobstat';
每个命令执行得很好,但我无法使用新用户登录。 错误是:
无法打开登录请求的数据库“mobstat”。登录失败。
我已经尝试过谷歌了,但还没有结果。 我的客户是DBeaver。
答案 0 :(得分:1)
USE master;
GO
CREATE LOGIN mobstat WITH PASSWORD = 'mobstat123';
GO
CREATE DATABASE mobstat COLLATE SQL_Hungarian_CP1250_CI_AS;
GO
-- You were creating a schema and a User before you have created a database
USE [mobstat]
GO
CREATE USER mobstat FOR LOGIN mobstat;
GO
EXEC sp_addrolemember N'db_owner', N'mobstat';
GO
CREATE SCHEMA [mobstat] AUTHORIZATION [mobstat]
GO