Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to restrict Users from running SQL.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 08/31/2012 :  15:33:24  Show Profile  Reply with Quote
We use SQL Server 2005. We have created a SQL Server Login called RUNSQLQUERYUSER. We have the following questions:

1. How to limit RUNSQLQUERYUSER from executing SQL queries using SQL Server Management Studio between 9:00 AM and 5:00 PM? How to implement that? Therefore if RUNSQLQUERYUSER runs a query at 8:00 AM we let them
but after 9:00 AM we don't let this user execute queries.

2. If RUNSQLQUERYUSER runs a SQL query before 9:00 AM but the query takes more than 30 minutes we need to stop it.

3. If RUNSQLQUERYUSER runs a SQL query before 9:00 AM but the query is still running at 9:00 AM we need to stop it.


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 08/31/2012 :  18:30:39  Show Profile  Reply with Quote
run a scheduled job at 9 to grant required access to login and run a job by 5 pm to revoke it.

for stopping query check the execution time using dmv and then kill process

SQL Server MVP

Go to Top of Page

Most Valuable Yak

15732 Posts

Posted - 08/31/2012 :  20:08:44  Show Profile  Visit robvolk's Homepage  Reply with Quote
Alternatively you can use a logon trigger to prevent that user from even connecting to SQL Server during those hours. It has more flexibility than permissions as you can also check which application it's using, which machine it's connecting from, etc.

You can read more about them here:

And for future reference, if you upgrade to SQL Server 2008 Enterprise Edition, you can use the Resource Governor to control how many resources are used for certain users/connections.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000