Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create user and assign permission to user in LocalDB in Visual Studio

Can someone please tell me how I can create a user with a password and grant it owner permission to a database that I created in LocalDB in Visual Studio.

It creates a user with no login but I need to create one with a password and owner rights to a database.

like image 612
SP1 Avatar asked Sep 16 '15 00:09

SP1


1 Answers

  • Open SQL Server Object Explorer (e.g. from the Visual Studio View menu)
  • Expand your localdb instance in the tree (e.g. (localdb)\MSSQLLocalDB)
  • Right click your database and select New Query...
  • Execute the following sql:

...

CREATE LOGIN [SomeUser] WITH PASSWORD = 'topsecret';
CREATE USER [SomeUser] FOR LOGIN [SomeUser];
exec sp_addrolemember 'db_owner', 'SomeUser'
like image 101
ngm Avatar answered Sep 20 '22 14:09

ngm