John Egbert John Egbert - 6 months ago 15
SQL Question

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?

I need to create a user to use in a connection string that doesn't use Integrated Security.

Answer

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.

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