Re: does sql user need to be an admin?

From: Dan Guzman (danguzman@nospam-earthlink.net)
Date: 12/10/02


From: "Dan Guzman" <danguzman@nospam-earthlink.net>
Date: Mon, 9 Dec 2002 22:16:45 -0600


User accounts need to be granted access to SQL Server in order to
connect; file permissions do not control database access. By default,
members of the local Administrator group access SQL Server via the
'BUILTIN\Administrators' login. This account is a member of the
powerful sysadmin server role and should not be used for routine
application access.

Below are scripts for the basic SQL Server security administration tasks
needed to grant an account permissions to connect and use a database
object. See the SQL Server Books Online
<adminsql.chm::/ad_security_05bt.htm> for details and instructions for
the Enterprise Manager equivalents.

Grant a Windows account access to SQL Server:

    EXEC sp_grantlogin 'MyDomain\MyAccount'
    GO

Grant a Windows account access to a SQL Server database:

    USE MyDatabase
    EXEC sp_grantdbaccess 'MyDomain\MyAccount'
    GO

Add a database role:

    USE MyDatabase
    EXEC sp_addrole 'MyRole'
    GO

Grant object permissions to a role:

    USE MyDatabase
    GRANT SELECT, INSERT, UPDATE, DELETE
    ON MyTable TO MyRole

Add a user to a database role:

    USE MyDatabase
    EXEC sp_addrolemember 'MyRole', 'MyDomain\MyAccount'
    GO

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
-----------------------
SQL FAQ links (courtesy  Neil Pike):
http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------
"Dan C." <danc@nospam.com> wrote in message
news:057701c29fec$669c9030$d3f82ecf@TK2MSFTNGXA10...
> I have an application that logs onto SQL server using
> integrated Windows authentication.
>
> On client machine:
> Created an account called "APPUSER" that belongs to
> the "Users" group. The application (actually a web app)
> uses impersonation to create a database connection using
> that account.
>
> On server machine:
> Created the same account and also added it to SQL server
> with rights to the desired table.
>
> The problem I have is that if that account does not belong
> to the "Administrators" group, I get a message that the
> user is not a member of a trusted SQL connection. If the
> account belongs to the administrators group then
> everything works perfectly.
>
> I do not want clients to use an administrative account to
> access the database. Does anybody know what I am
> missing? "Everyone" has "full control" to the sql server
> directory.
>
> Thanks in advance.
>
> Dan


Relevant Pages

  • Re: No db access after publishing web site
    ... GRANT UPDATE TO ... If I detach and attach this database on a different PC (according that PC ... Cannot open database "pago" requested by the login. ... Are you detaching/attaching the SQL Server Express database correctly ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Problems with WebParts
    ... to a database called aspnetdb. ... > The connection string specifies a local SQL Server Express instance using a ... > server account must have read and write access to the applications directory. ... > This is necessary because the web server account will automatically create ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: DTS Package fails when Scheduled
    ... Apparently I was unable to pass on the database password when runninig the ... Make sure SQL Server Agent account has the correct rights/permissions. ... scheduled job under this context, I still received the error, even though I ...
    (microsoft.public.sqlserver.dts)
  • Problems with WebParts
    ... The connection string specifies a local SQL Server Express instance using a ... database location within the applications App_Data directory. ... server account must have read and write access to the applications directory. ... logged-in user needs the dbcreator privilege in the appropriate SQL Server ...
    (microsoft.public.dotnet.framework.aspnet)
  • Cant create a subcription for SQL Server 2005 Mobile
    ... SQL Server 2005 database but I haven't had any success. ... Windows account which has full admin permissions. ... I selected the New Subscription Wizard on the node of my ...
    (microsoft.public.sqlserver.ce)