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?

     

    Verified Answer?

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

    by:Posted 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]

    This content is available to Experts Exchange members

    See the answer now
    with your Free 30 Day Trial

    Get unlimited access to solutions & experts

    • 4,169,477 solved questions
    • 3,805 articles & videos
    • 15,413 tech experts

    Get Access Now

    Ask Your Tech Question. Get Expert Solutions.We will email you when an expert has commented on your question.

    We will never share this with anyone. Privacy Policy Terms of Use

    Select topics

    You may select up to five topics.

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers

    201508-LO-Qu-072

    RELATED TOPICS view all topics

    1. .NET Programming
      (129,717)
    2. ASP.NET
      (121,160)
    3. Visual Basic.NET
      (90,486)
    4. MS Development
      (48,486)
    5. Editors IDEs
      (25,028)
    6. Programming
      (50,760)
    7. MS SQL Server
      (152,770)
    8. JavaScript
      (116,291)
    9. XML
      (19,633)
    10. Programming Languages
      (19,432)