Programmatically Setup SQL Permissions From Windows App?

    Question by:
    On

    Topics:

    I'd link to setup SQL Database users and permissions from a Windows App (VS2005 C#).

    I currently have to Install and set SQLExpress 2005 permissions using the (free) Management Studio Express on every computer I install my App.

    Would be nice to have a pop-up window (secured) within my Win App that I could simply set new database users and permissions.

    I suppose someone else has already done this, but I didn't find anything on the Internet.

    I currenly open the Management Studio -> Security -> Logins -> New Login -> <create user then set 'User Mappings'...

    I'm using 'Integrated Security' and realize that I need to access the OS (XP-Pro) users and groups, don't know if that's possible.

    Q. How can I programmatically (code)  setup Users, Groups, Permissions on SQLExpress 2005?

    Good Question?
    0
     

    ?

    The member who asked this question verified this comment provided the solution that solved their problem.

    Accepted Solution on 2007-09-27 at 09:04:39ID: 19972384

    Some example script:
    -- creat LOGIN
    CREATE LOGIN [xxx] WITH PASSWORD=N'xxxxx', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
    GO
    EXEC sys.sp_addsrvrolemember @loginame = N'xxx', @rolename = N'rolename'  -- e.g. sysadmin

    use [your database]
    CREATE USER [aaaa] FOR LOGIN [xxx] WITH DEFAULT_SCHEMA=[dbo]

    exec sp_addrolemember 'db_owner', [aaaa]

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers

    201511-LO-Qu-074

    Extend your technology team with the Experts Exchange community.

    — trusted by —

    Who answers my questions?Our community has technology experts around the world.

    käµfm³d   👽

    9

    Articles

    7,460

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • Visual Basic.NET
    • ASP.NET
    • Regular Expressions

    Alexandre Simões

    6

    Articles

    1,022

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • JavaScript
    • Visual Basic.NET
    • ASP.NET

    it_saige

    1,038

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • Visual Basic.NET
    • ASP.NET
    • Active Directory

    AndyAinscow

    11

    Articles

    3,144

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • System Programming
    • Visual C++.NET
    • C++

    Lokesh B R

    205

    Solutions

    Expert in:

    • .NET Programming
    • ASP.NET
    • C#
    • Visual Basic.NET

    Fernando Soto

    5,013

    Solutions

    Expert in:

    • .NET Programming
    • Visual Basic.NET
    • C#
    • ASP.NET
    • Editors IDEs

    zephyr_hex

    2,543

    Solutions

    Expert in:

    • MS SharePoint
    • MS SQL Server 2005
    • Microsoft IIS Web Server
    • Windows 2003 Server
    • Windows XP

    Kyle Abrahams

    2,141

    Solutions

    Expert in:

    • .NET Programming
    • ASP.NET
    • C#
    • MS SQL Server
    • MS SQL Server 2008

    Dan McFadden

    461

    Solutions

    Expert in:

    • Microsoft IIS Web Server
    • Windows Server 2008
    • Windows Server 2012
    • ASP.NET
    • Active Directory

    RELATED TOPICS view all topics

    1. .NET Programming
      (131,139)
    2. ASP.NET
      (122,121)
    3. Visual Basic.NET
      (91,459)
    4. MS Development-Other
      (48,696)
    5. Editors IDEs
      (25,097)
    6. Programming-Other
      (51,630)
    7. MS SQL Server
      (154,727)
    8. JavaScript
      (117,367)
    9. XML
      (19,778)
    10. WCF
      (4,300)