Tuesday, May 15, 2012

Running SQL Server Agent jobs on demand by unauthorized users


PROBLEM:
You configure some SQL Server Agent jobs to run schedule maintenance tasks, but there is sometimes the need for these tasks to be executed on demand.
You want other users just to run the job, without modifying it.
For those users SQL Server Agent node in Object Explorer is not visible because they have minimum permissions (no SQLAgentOperatorRole)

SOLUTION:
Use database impersonation by using EXECUTE AS

USE [master]
GO
CREATE LOGIN [runSqlAgentJobsLogin] WITH PASSWORD=N'123%123', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
GO

USE [msdb]
GO
CREATE USER [runSqlAgentJobsLogin] FOR LOGIN [runSqlAgentJobsLogin]
GO
EXEC sp_addrolemember N'SQLAgentOperatorRole', N'runSqlAgentJobsLogin'
GO
CREATE PROCEDURE [RUN_BACKUP_SP] WITH EXECUTE AS 'runSqlAgentJobsLogin'
AS
EXEC sp_start_job @JOB_NAME = 'My_Backup'
GO
GRANT EXECUTE ON [MSDB].[DBO].[RUN_BACKUP_SP] TO [DOMAIN\User]
GO

Now, connect as an unauthorized user to one of the databases and run the following. The user can only run the procedure that runs the job, he cannot see the job or modify it

EXEC [MSDB].[DBO].[RUN_BACKUP_SP]

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

Monday, May 14, 2012

Give control over access to SQL Server Agent

PROBLEM:
You need to give control over access to SQL Server Agent

SOLUTION:
When users who are not members of one of the following roles are connected to SQL Server in SQL Server Management Studio, the SQL Server Agent node in Object Explorer is not visible. A user must be a member of one of these fixed database roles or a member of the sysadmin fixed server role to use SQL Server Agent
  • SQLAgentUserRole
  • SQLAgentReaderRole
  • SQLAgentOperatorRole
The following command add 'LoginName' to 'SQLAgentReaderRolerole. SQLAgentReaderRole includes all the SQLAgentUserRole permissions as well as permissions to view the list of available multiserver jobs, their properties, and their history. Members of this role can also view the list of all available jobs and job schedules and their properties, not just those jobs and job schedules that they own. SQLAgentReaderRole members cannot change job ownership to gain access to jobs that they do not already own. Only the Jobs node in SQL Server Management Studio Object Explorer is visible to members of the SQLAgentReaderRole

USE [msdb]
GO
EXEC sp_addrolemember N'SQLAgentReaderRole', N'LoginName'
GO

USE [msdb]
GO
EXEC sp_droprolemember N'SQLAgentReaderRole', N'LoginName'
GO

More details:
http://msdn.microsoft.com/en-us/library/ms188283.aspx
http://msdn.microsoft.com/en-us/library/ms187901.aspx

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

Deprecated Database Engine Features in SQL Server 2012

PROBLEM:
What are the SQL Server future releases deprecated features that should not be used in new applications?

SOLUTION:
Here is the list of deprecated SQL Server database engine features that are still available in SQL Server 2012 and scheduled to be removed in a future release
http://technet.microsoft.com/en-us/library/ms143729.aspx

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

Breaking Changes to Database Engine Features in SQL Server 2012

PROBLEM:
What are the changes in SQL Server 2012 that might break applications, scripts, or functionalities that are based on earlier versions of SQL Server?

SOLUTION:
You might encounter these issues when you upgrade
http://technet.microsoft.com/en-us/library/ms143179.aspx#CurrentVersion


If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!



Tuesday, May 8, 2012

Could not find property or field 'LAT' for type 'Microsoft.SqlServer.Types.SqlGeography'

PROBLEM:
You are trying to query geography data type
SELECT GEOLOCATION.LAT, GEOLOCATION.LONG FROM GEOLOCATION_TABLE
or
select geolocation.lat, geolocation.long from geolocation_table
and gets the following error:
Could not find property or field 'LAT' for type 'Microsoft.SqlServer.Types.SqlGeography'
or
Could not find property or field 'lat' for type 'Microsoft.SqlServer.Types.SqlGeography'

SOLUTION:
CLR types  are case sensitive by default. You should use "Lat" and "Long"
SELECT GEOLOCATION.Lat, GEOLOCATION.Long FROM GEOLOCATION_TABLE;

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

Tuesday, May 1, 2012

TFS Build Error - Different checksum values given for


PROBLEM:
When building projects using TFS Build (or MSBuild) you get the following error:
Different checksum values given for ..

SOLUTION:
Check that the full path of the file (or the file shortcut) is not too long for MSBuild, try to shorten it and build again.

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!


TFS Build Error - CSC: Source file could not be found

PROBLEM:
When building projects using TFS Build (or MSBuild) you get the following error:
CSC: Source file could not be found

SOLUTION:
Check that the full path of the file (or the file shortcut) is not too long for MSBuild, try to shorten it and build again.

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!