[英]How can I create a user in SQL Server Express database I added to my project?
How can I create a SQL user in a SQL Server Express database that I added to my project? 如何在添加到项目的SQL Server Express数据库中创建SQL用户?
I need to create a user to use in a connection string that doesn't use Integrated Security. 我需要创建一个要在不使用Integrated Security的连接字符串中使用的用户。
You would need to create a SQL Authenticated login first with CREATE LOGIN then add a user associated with that login to your database by using CREATE USER . 您首先需要使用CREATE LOGIN创建一个SQL身份验证登录名,然后使用CREATE USER将与该登录名关联的用户添加到数据库中。
USE [master]
GO
CREATE LOGIN [JohnEgbert] WITH PASSWORD=N'YourPassword',
DEFAULT_DATABASE=[YourDB], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [YourDB]
GO
CREATE USER [JohnEgbert] FOR LOGIN [JohnEgbert] WITH DEFAULT_SCHEMA=[dbo]
GO
If you create a SQL login and a SQL user without errors, but then get an error when trying to connect, you may have the SQL Authentication mode disabled. 如果创建的SQL登录名和SQL用户没有错误,但是在尝试连接时出现错误,则可能禁用了SQL身份验证模式。 To check, run: 要检查,请运行:
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly')
If this returns 1, then SQL Authentication (mixed mode) is disabled. 如果返回1,则禁用SQL身份验证(混合模式)。 You can change this setting using SSMS, regedit, or T-SQL: 您可以使用SSMS,regedit或T-SQL更改此设置:
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
Then restart the SQL Server service, and create a login and a user, here with full permissions: 然后重新启动SQL Server服务,并创建一个具有完全权限的登录名和一个用户:
CREATE LOGIN myusername WITH PASSWORD=N'mypassword',
DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
EXEC sp_addsrvrolemember 'myusername', 'sysadmin'
CREATE USER myusername FOR LOGIN myusername WITH DEFAULT_SCHEMA=[dbo]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.