| Author |
Topic |
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-15 : 17:37:56
|
| Hello,I am trying to create a SQL Server Security Login to access to a database.That login will be used by my application Linq to SQL context.What is the correct rolename for this kind of user. I have the following: create login WAT with password = 'wat', default_database = WAT, default_language = english; go exec sys.sp_addsrvrolemember @loginame = N'WAT', @rolename = N'sysadmin' use WAT; goShould I use sysadmin? I think this is not correct.Am I creating the login correctly?Thanks,Miguel |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-15 : 17:50:42
|
| Basically, read and write using Linq, well converted to SQL Queries. I tried exec sys.sp_addsrvrolemember @loginame = N'WAT', @rolename = N'db_owner'But I got the error:Msg 15402, Level 11, State 1, Procedure sp_addsrvrolemember, Line 23'db_owner' is not a fixed server role.What is the correct value for db_owner?Do I need to change something on my T-SQL?And when I backup the database and restore can I also backup restore the login?Thanks,Miguel |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-15 : 18:15:40
|
Could you please tell me how to create the database role db_owner?I am using the following to create this databaseexec sp_configure 'filestream access level', 2;reconfigure;go use mastergoif exists (select name from sys.databases where name = N'WAT') drop database WATcreate database WAT on primary ( name = 'WAT_Data', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_Data.mdf', size = 20MB, maxsize = 2GB, filegrowth = 10MB ),filegroup WAT contains filestream ( name = 'WAT_File', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_File.ndf')log on ( name = 'WAT_Log', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_Log.ldf', size = 10MB, maxsize = 200MB, filegrowth = 5MB )goif exists (select * from sys.server_principals where name = N'WAT')drop login WATgocreate login WATwith password = 'watpass', default_database = WAT,default_language = english;goexec sys.sp_addsrvrolemember @loginame = N'WAT', @rolename = N'db_owner'use WAT;go-- Create database tables I am using this not just to create the database for the first time but also if I want to recreated from scratch again.Thank You,Miguel |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-15 : 18:25:42
|
Yes, I tried that before:create login WATwith password = 'watpass', default_database = WAT,default_language = english;goexec sys.sp_addrolemember @membername = N'WAT', @rolename = N'db_owner' But I get the error:User or role 'WAT' does not exist in this database.Which is strange because I just add it before ... |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-15 : 21:23:22
|
| I created the following T-SQL that creates the login, the user and the database.First it checks if there is already a user, login or database and if so deletes all them.This is because I would like to use this code to create or recreate everything from scratch.Could you, please, tell me if I am doing this correctly?-- Define file stream access level exec sp_configure 'filestream access level', 2;reconfigure;go -- Start connectionuse mastergo-- Drop userif exists (select name from sys.database_principals where name = N'WAT')drop user WATgo-- Drop loginif exists (select * from sys.server_principals where name = N'WAT')drop login WATgo-- Drop databaseif exists (select name from sys.databases where name = N'WAT') drop database WAT -- Create database, filegroup and logcreate database WAT on primary ( name = 'WAT_Data', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_Data.mdf', size = 20MB, maxsize = 2GB, filegrowth = 10MB ),filegroup WAT contains filestream ( name = 'WAT_File', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_File.ndf')log on ( name = 'WAT_Log', filename = 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WAT_Log.ldf', size = 10MB, maxsize = 200MB, filegrowth = 5MB )go-- Create logincreate login WATwith password = 'watpass', default_database = WAT,default_language = english;go-- Create usercreate user WAT;use WAT;create user WAT for login WAT;go-- Define roleexec sys.sp_addrolemember @membername = N'WAT', @rolename = N'db_owner'-- Start connectionuse WAT;go-- Create tables and relationshipsTwo things I notice:1 - When I check the login the "Enforce password expiration" is not selected. Should it be?2 - The login is also mapped to master database as public. Am I missing something? In relation to WAT is mapped as db_owner and public.Finally, when I do a backup of this database can I include everything (login, user, etc) and restore it later?Thank You,Miguel |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2010-06-16 : 06:05:30
|
| I have just one more question:Should I create a role with permissions equal to db_owner and then associate that role to the user instead of using db_owner?Is it more correct?How can I do that?Thank You,Miguel |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|