Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.

Message:
Cannot grant deny or revoke permissions to sa dbo entity owner information_schema sys or yourself.

This message occurs when yoy try to revoke permissions for the following users:
– yourself
– sa
– dbo
– entity owner
– information_schema
– sys

Resolution:
If you wanted to grant/revoke (or) deny permissions for yourself instead of running the query using yor own login
You can alternatively
– Login as a different user and run the query.
– Ask another SQL Server user to grant/revoke (or) deny permissions to you.
– Ask your DBA to grant/revoke (or) deny permissions.

sql server configuration manager remote procedure call failed

When you try to start a service from SQL Server Configuration manager you get the below error:

The remote procedure call failed

Fix:

Try to run the service from services.msc instead of running it from SQL Server Configuration manager.
If you are unable to start the service in services.msc, change the service startup type first and give a try starting the service.

sql server affinity mask setting

table.hovertable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.hovertable th {
background-color:#c3dde0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.hovertable tr {
background-color:#d4e3e5;
}
table.hovertable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}

Below is the complete guide to setting SQL Server affinity:

SQL Servers affinity tells the server to use specific processors to perform a certain task.
For example, affinity I/O mask can be used to configure sql server processors affinity to Input output operations.

How to set the affinity in sql server?

SQL Servers affinity on a multiprocessor system can be set by using sp_configure.

Sample script:
[sql]
sp_configure ‘show advanced options’, 1
GO
sp_configure
[/sql]

When you execute the above script you will be able to find 5 items for affinity:

  • affinity I/O mask – For setting sql server disk I/O affinity to cpu’s on 32bit processor
  • affinity mask – For SQL Server affinity to cpu’s on 32bit processor
  • affinity64 I/O mask – For setting sql server disk I/O affinity to cpu’s on 64bit processor
  • affinity64 mask – For SQL Server affinity to cpu’s on 64bit processor
SQL Server affinity Mask Configuration

Changing the values using sp_cofigure

Below table gives you the details of the values that can be set and the processors used by sql server:

Configured value Allow SQL Server on processors number
1 0
3 0 , 1
7 0, 1, 2
15 0, 1, 2, 3
31 0, 1, 2, 3, 4
63 0, 1, 2, 3, 4, 5
127 0, 1, 2, 3, 4, 5, 6

Below piece of code changes the affintiy mask value to 3:
[sql]
sp_configure ‘show advanced options’, 1
GO
reconfigure
GO
sp_configure ‘affinity mask’, 3
GO
reconfigure
GO
[/sql]
Message: Configuration option ‘affinity mask’ changed from 0 to 3. Run the RECONFIGURE statement to install

If you have set an invalid value as per your processor configuration you get the error below error:

Msg 5832, Level 16, State 2, Line 1
The affinity mask specified does not match the CPU mask on this system.

Link

CONCAT_NULL_YIELDS_NULL

CONCAT_NULL_YIELDS_NULL Can be used to control the Concatenation results of stings with NULLS.

When turned on:
Concatenation of string with NULL Results in NULL.

When turned Off:
Concatenation of string with NULL Results in String itself.

Sample Queries:
[sql]
SET CONCAT_NULL_YIELDS_NULL ON

SELECT ‘TestString’ + NULL AS Result
–Results in NULL
SET CONCAT_NULL_YIELDS_NULL OFF

SELECT ‘TestString’ + NULL AS Result
–Results in TestString
[/sql]
The first result would be NULL and the Second result would be TestString.

In the above query the Impact of changing the property value can be clearly seen.

CONCAT_NULL_YIELDS_NULL setting can be changed in Session or in Database.

Setting CONCAT_NULL_YIELDS_NULL value in Session:
[sql]
SET CONCAT_NULL_YIELDS_NULL ON
SET CONCAT_NULL_YIELDS_NULL OFF
[/sql]

If this setting is changed in the Session then the impact of changing this value can be seen in the current session only. All the other session will have its default behaviour.

Setting CONCAT_NULL_YIELDS_NULL value for a Database:
[sql]
ALTER DATABASE <<databasename>> SET CONCAT_NULL_YIELDS_NULL OFF
ALTER DATABASE <<databasename>> SET CONCAT_NULL_YIELDS_NULL ON
[/sql]
If the value of CONCAT_NULL_YIELDS_NULL is not set in the query then the database property for CONCAT_NULL_YIELDS_NULL is used By default .

How to check the current setting of CONCAT_NULL_YIELDS_NULL?

The Below query fetches the session value for the CONCAT_NULL_YIELDS_NULL property.
[sql]
SELECT SESSIONPROPERTY(‘CONCAT_NULL_YIELDS_NULL’)
–Result 1 if set to ON, 0 if Set to OFF
[/sql]

The Below query fetches the database value for the CONCAT_NULL_YIELDS_NULL property.
[sql]
SELECT NAME,IS_CONCAT_NULL_YIELDS_NULL_ON FROM SYS.DATABASES
–Result 1 if set to ON, 0 if Set to OFF
[/sql]

Point to Note:

– Some clients Like SQL Server Management studio by default send the CONCAT_NULL_YIELDS_NULL ON command while initiating each database connection.
Hence even after changing the database property the result cannot be seen in SSMS.

– Setting this value in stored procedures may cause the procedure to recompile every time its executed.

– This setting in future versions of SQL Server is going to be Always ON, So be cautious while using this.

http://support.microsoft.com/kb/294942
http://msdn.microsoft.com/en-us/library/ms176056.aspx

Causes For Network Related Errors in SQL Server

Following are the main reasons for network related errors in SQL Server.

1) Server/Instance name is wrong
Fix: Check for the correct name of the Server/Instance and try to connect again

2) SQL Server Service is not running on the Server Machine.
Fix: Start the SQL Server service on the Server Machine.
Steps to start the SQL Server Service:
– Run -> Services.msc
– RightClick on SQL Server (MSSQLSERVER)
– Click on Start

Start SQL Server Service
Start SQL Server Service

3) SQL Server instance Service is not running on the Server Machine.
Fix: Start the SQL Server instance service on the Server Machine.
Steps to start the SQL Server instance Service:
– Run -> Services.msc
– RightClick on SQL Server (instancename)
– Click on Start

4) SQL Server Browser Service is not running on the Server Machine.
Fix: Start the SQL Server Browser service on the Server Machine.
Steps to start the SQL Server Browser Service:
– Run -> Services.msc
– RightClick on SQL Server Browser
– Click on Start

5) TCP/IP is disabled on the Server Machine.
Fix: Enable TCP/IP
Steps to enable TCP IP On SQL Server
Open SQL Server Configuration Manager
– Allprograms ->( Microsoft SQL Server 2008 R2 (or) Microsoft SQL Server 2008 (or) Microsoft SQL Server 2005 ) -> SQL Server Configuration Manager

Open SQL Server Configuration Manager
Open SQL Server Configuration Manager

– Expand SQL Server Network configuration
– Click on protocols for MSSQLSERVER (If its an instance click on the respective instance name)
– RightClick on TCP/IP and click on enable

Enable TCP IP
Enable TCP IP

6) Firewall does not allow connections to SQL Server Service.
Fix: Add exception to Firewall to allow connections to SQL Server Service.

7) Firewall does not allow connections to SQL Browser Service.
Fix: Add exception to Firewall to allow connections to SQL Browser Service.

8 ) Remote connections are disabled on SQL Server
Fix: Allow remote connections on sql server
Steps:
– Connect to SQL Server on SSMS
– RightClick on Server
– Click On Properties
– In the Server Properties Popup Select Connections
– Check the Allow remote connections to Server and click on OK

Allow Remote Connections to Server
Allow Remote Connections to Server

9) Time out errors due to network latency
Fix: Increase Remote Query Time out
Steps:
– Connect to SQL Server on SSMS
– RightClick on Server
– Click On Properties
– In the Server Properties Popup Select Connections
– Increase the Remote query timeout value and click on OK

Remote Query Time Out
Remote Query Time Out

10) Invalid Credentials
Fix: Fetch the latest creadentials to login into the server or ask the administrator to give your credentials necessary oermissions on the server.

SHRINK Database

Following are the Steps to SHRINK Database in SQL Server.

1) Connect to the SQL Server in SSMS

2) Expand Databases

3) RightClick on the Database to be shrinked, Click on Tasks then on Shrink.

4) Here you will have two options:

Shrink Database
Shrink Files

Using Database option you can shrink the database as a whole
Files option lets you shrink each file associated with the database seperately.

Shrink Database
Shrink Database

5) Select Database

6) Now in the Shrink Database Popup Click OK

Shrink Database Popup
Shrink Database Popup

Why is SQL Server consuming Lot of RAM

Why is SQL Server consuming Lot of RAM

There could be multiple reasons why SQL Server is consuming lot of physical memory (RAM).

Following are the few that I would like to list out:

1) Performance of the server could be bad as the queries that are hitting the sever are not optimal.
You can further fine tune such queries.

2) Maximum and Minimum server memory configuration is not set up properly.
You can set up maximum server memory configuration so that it doesnt eat up whole of the RAM.

Following are the Steps to configure sql server memory allocation:

  • Connect to the SQL Server in SQL Server management studio
  • Right click on the server and click on properties
  • Now the Server Properties window pops up.
    In the Server Properties window Select Memory.
    Now check the values of
    Minimum Server Memory(in MB) and Maximum Server Memory(in MB)

    Configure Maximum And Minimum SQL Server Memory
    Configure Maximum And Minimum SQL Server Memory
  • Adjust these values to opimal memory values as per your SQL Server’s memory requirement.

Note: Be aware that changing the memory configuration of SQL Server might give you very bad results. Hence be cautious before making such changes.
You might also get There is insufficient system memory in resource pool ‘default’ to run this query error if memory configuration is bad.

enable xp_cmdshell on SQL Server

How to enable xp_cmdshell on SQL Server 2005/2008?

If xp_cmdshell is disabled on SQL Server you get the following error:
Query:
[sql]
EXEC xp_cmdshell ‘dir’
[/sql]


SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure. For more information about enabling ‘xp_cmdshell’, see “Surface Area Configuration” in SQL Server Books Online.

In order to enable this SQL Server has to be configured to allow access to procedure xp_cmdshell.

Following are the steps for that:

[sql]
EXEC sp_configure ‘show advanced options’, 1
reconfigure
GO
[/sql]

This enables to show advanced options by sp_configure.

Now if you execute sp_configure
[sql]
EXEC sp_configure
[/sql]

The following will be the output in the results window:

xp_cmdshell disabled
xp_cmdshell disabled

Run the following query to enable this:
[sql]
EXEC sp_configure ‘xp_cmdshell’,1
reconfigure
GO
[/sql]

Now you will be able to execute xp_cmdshell.

More about using sp_configure can be found here

Enable OPENROWSET

When you try to execute queries involving OPENROWSET on SQL Server you get the following error:


SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries’ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries’, see “Surface Area Configuration” in SQL Server Books Online.

This occurs basically when Ad Hoc Distributed Queries is disabled.

So how to enable this:

Simple by just changing the configuration of SQL Server using sp_configure
More about using sp_configure can be found here

Following are the steps to enable Ad Hoc Distributed Queries on SQL Server:

Open SQL Server Management Studio (SSMS)

Create a new query on master database
Run the following query:
[sql]
sp_configure ‘show advanced options’,1
reconfigure
[/sql]

This enables sp_configure to show advanced options

Now run sp_configure

As shown in the screenshot below you can see ‘Ad Hoc Distributed Queries’ having config_value of 0

Ad Hoc Distributed Queries disabled
Ad Hoc Distributed Queries disabled

To enable this run the below query

[sql]
sp_configure ‘Ad Hoc Distributed Queries’,1
reconfigure
[/sql]

Now if you run sp_configure you will find it enabled as shown in the screen shot below

Ad Hoc Distributed Queries Enabled
Ad Hoc Distributed Queries Enabled

If you run the query with OPENROWSET now you do not get the same error again.

Enjoyed enabling Ad Hoc Distributed Queries? I enjoyed it 🙂

using sp_configure sql server

using sp_configure in sql server explained in depth.

The procedure sp_configure Displays or changes global configuration settings for the current server.

Syntax:


sp_configure

Parameters of sp_configure:

Parameter_name Type Length Prec Scale Param_order Collation
@configname varchar 35 35 NULL 1 SQL_Latin1_General_CP1_CI_AS
@configvalue int 4 10 0 2 NULL

@configname is the configuration name. If this value is not
specified then all the configuration options are listed.

@configvalue is used to set the new value to the
configuration option provided in @configname. Its default value is null.

The maximum and minimum values for each configuration name
can be found by executing the sp_configure procedure directly.

The output of executing sp_configure directly will be as
follows(depending upon the current configuration the results will change):

sp_configure screen shot

The Screen Shot Shown Above Changes As Per The Current Sql Server Configuration.

How to change the sql server configured value:(be cautious, changing the values with out knowledge would harm your servers instance)

Syntax:
sp_configure ‘<<Configuration Name>>’,'<<Configuration Value>>’

One fo the simple example would be:

sp_configure 'show advanced options', 1
GO

This changes the configuration value of ‘show advanced options’ to 1. This means the sqrver instance is now configured to show the advanced options.

In order to apply the changed confuguration to the servers instance the reconfigure command has to be run.

Syntax:
reconfigure
GO

Now the updated value is configured to the instance. There are some configurations which do not apply immedietely but will need a Server service restart.

Now if the sp_configure procedure is run again, the advanced configuration options are shown as shown in the below image:

How to check the configured value that is currently being used by the instance?

Running the procedure sp_configure with out parameters gives a resultset which contains the column run_value.

This value is the value that is currently being used.Some configurations which do not apply immedietely will need a Server service restart. They can be found by analysing the run_value Column for sp_configure.

So the difference between Config_Value and run_value is that config_value is the value that the configration name is configured, run_value  is the value that the instance is currently using.

Unless the reconfigure command is run the config_value and the run_value does not match, There are some configurations for which even after running the reconfigure command the config_value does not match with run_value, for these configurations sql server service has to be restarted after running the reconfigure command.