0

Without giving read/write permissions to ALL USERS, they are not able to to write to a SQL Server database.

Currently, it is done manually. And the manual way is too cumbersome to the end users.

Is there any way in a VB.NET setup project, to give permissions to all users during installation?

slayernoah
  • 4,382
  • 11
  • 42
  • 73
Pooh
  • 105
  • 1
  • 3
  • 12

1 Answers1

0

If your users are declared as users of the database, you can launch that SQL script :

DECLARE @name NVARCHAR(128)

DECLARE @users TABLE(name NVARCHAR(128))

INSERT INTO @users
SELECT name
FROM sys.sysusers 
WHERE issqluser = 1
    AND [sid] IS NOT NULL
    AND hasdbaccess = 1
    AND name <> 'dbo'

WHILE EXISTS(SELECT 1 FROM @users)
BEGIN
    SELECT TOP 1 @name = name 
    FROM @users

    EXEC sp_addrolemember N'db_datawriter', @name
    EXEC sp_addrolemember N'db_datareader', @name

    DELETE @users 
    WHERE name = @name
END
Ivandolchevic
  • 184
  • 1
  • 3