Quantcast
Channel: SQL Errors – SQLSERVERLEARNER
Viewing all 74 articles
Browse latest View live

Enable OPENROWSET

$
0
0

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:

sp_configure 'show advanced options',1
reconfigure

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

sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

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 :)


The media family on device is incorrectly formed. SQL Server cannot process this media family Error: 3241

$
0
0

When you try to restore a backup of the database you get the following error:


The media family on device ” is incorrectly formed. SQL Server cannot process this media family.
RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)

This error occurs due to the following problems:

Fix:

  • If you feel backup could be corrupted take the backup again
  • If you are using FTP then use it in binary mode to copy the backup file into local drive
  • If the versions are different then update the SQL Server on the system into which the backup has to be restored
  • Verify the database backup to check what the issue is.
    Following post helps you verify your database backup: Verify SQL Server Database Backup
  • More about using restore verify only this option in SQL Server can be found here

enable xp_cmdshell on SQL Server

$
0
0

How to enable xp_cmdshell on SQL Server 2005/2008?

If xp_cmdshell is disabled on SQL Server you get the following error:
Query:

EXEC xp_cmdshell 'dir'


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:

EXEC sp_configure 'show advanced options', 1
reconfigure
GO

This enables to show advanced options by sp_configure.

Now if you execute sp_configure

EXEC sp_configure

The following will be the output in the results window:

xp_cmdshell disabled

xp_cmdshell disabled

Run the following query to enable this:

EXEC sp_configure 'xp_cmdshell',1
reconfigure
GO

Now you will be able to execute xp_cmdshell.

More about using sp_configure can be found here

There is insufficient system memory in resource pool ‘default’ to run this query

$
0
0

When you try to execute a query on SQL Server you get the error: There is insufficient system memory in resource pool ‘default’ to run this query.

This memory problem would also occur in the following cases:

  • While executing a query on SSMS.
  • Trying to connect to a sql server in Sql server management studio
  • Trying to execute a SQL Query using OSQL in the command prompt
  • While executing a stored procedure
  • Using power shell to connect to SQL Server

In most of the cases the query would run successfully for some time and then encounter this error.

Possible reasons for this error:

  • The main reason would be un availability of allocated physical memory to sql server.
  • The ram would be completely used
  • SQL Server’s maximum memory allocation configured value has been reached.
  • Virtual memory is full

Fix for this error:

Try to allocate more memory to sql server server.
Steps to allocate memory are given below:

  • Connect to SQL Server management studio
  • Right click on the server and click on properties
  • Select Memory
  • Increase the value for Maximum Server Memory(in MB).

    SQL Server Properties window

    SQL Server Properties window

Try the following DBCC Commands

DBCC FREESYSTEMCACHE ('ALL')
DBCC FREESESSIONCACHE
DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

Kill all the unnecessary idle sessions on the server

Reduce the number of users on this server

Check the task manager and check if 100% of physical memory is being used.
If over loading of the server is the case then

  • Remove the applications on the server that are eating up much of the physical memory
  • increase the RAM on the server
  • increase virtual memory on the server

Optionally re start the SQL Server Service

Now check if the query is causing the same error.

Before making any changes to the server understand the pros and cons of the action performed by reading Microsoft documentation clearly.

Msg 2812, Level 16, State 62, Line 1 Could not find stored procedure ”

$
0
0

This error message occurs when SQL server interprets the text you have given as a stored procedure and cannot find a procedure with that name.

Possible reasons:

Summary:

Syntax error in sql code, Mistyped SQL Code
Stored procedure does not exist
Stored procedure got deleted
Missing schema name of the procedure in the query
Using exec with dynamic sql
Using Unicode with osql
Using extended stored procedures like xp_cmdshell on azure environment.

In Detail:

- Mistyped SQL Code

Example:

abcd

When you try to execute the above code you get the error
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure ‘abcd’.

- SQL Server interprets the single word that is sent as a query as the name of stored procedure with no parameters.

Example:
Create a stored procedure named abcd

CREATE PROCEDURE abcd
AS
SELECT * FROM SYS.tables

Now try to execute the below query:

abcd

The result would be the output of executing the procedure abcd.

So in order to avoid the above error, when querying sql server using a single word then make sure that the procedure with that name exists.

- You might expect the stored procedure with the name to exist but it isn’t.

To check if the procedure exists you can use the below query:

SELECT * FROM SYS.PROCEDURES WHERE NAME LIKE '%PROCEDURENAME%'

replace PROCEDURENAME with the name of the procedure.

- There could be a missing schema name of the procedure in the query

procedures with schema names would be like dbo.sp_abcd , products.sp_createproduct etc.

To find the schema name of the stored procedure you can use the following query:

select SCHEMA_NAME(schema_id),* from sys.procedures

You can also alternatively use the below query:

sp_help 'PROCEDURENAME'

- This error could also be due to using exec with dynamic sql.

Try opening and closing the braces after exec to avoid such error, also you can use sp_executesql.


exec (@dynamicsql)
--or
exec sp_executesql @dynamicsql

– when using unicode with osql

osql ignores Unicode files, you need to use -u switch with the osql command.

– Using SQL Azure and extended stored procedures
you could be using azure environment and SQL Azure does not have the extended stored procedures like xp_cmdshell.


Good coding standard would be to add exec statement beofore the name of the stored procedure.

sql server error 18456 – Login failed for user

$
0
0

Microsoft sql server error 18456 – Login failed for the user

When you try to connect to SQL Server you get the error 18456.

Error Message:

Cannot connect to Servername.
ADDITIONAL INFORMATION:
Login failed for user ‘username’. (Microsoft SQL Server, Error: 18456)

Additional details of the error when connecting from sql server management studio would be like this:

Server Name: Servername
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536

Reasons for the error:

User does not have access on the server
Provided user name is wrong
Provided Password is Wrong
Using windows login credentials for SQL Server authentication
Login for the user is disabled
Login was successfull but access to the server failed
Problems with SQL Service
Password for the user has to be changed
User does not have access to perform the specified acton on the server, Only has limited access
User does not have previlages to access the specific database, agent service etc

The exact actual reason behind this error can be seen in the Server Error log by the server administrator.

Also the error at a high level can be sorted out by the value of state in the error message.

According to MSDN Following is the list of error descriptions according to the state of the error: (SQL Server error 18456 error state list)

State Description Of The State Error
state 2 User ID is not valid.
state 5 User ID is not valid.
state 6 An attempt was made to use a Windows login name with SQL Server Authentication.
state 7 Login is disabled, and the password is incorrect.
state 8 The password is incorrect.
state 9 Password is not valid.
state 11 Login is valid, but server access failed.
state 12 Login is valid login, but server access failed.
state 18 Password must be changed.
state 23 SQL Service is shutting down.
state 38 User does not have access to the database.
Other States Internal Server Error


Resolution/Fix for sql server error 18456:

Contact the system administrator for help regarding this
Accoding to the state of the error, choose the possible solution.
Change password if the state is 18
For states 8 and 9 try to login with the correct password
For state 6 use windows authentication instead of sql server authentication
For state 2 and 5 use the correct userid to login



SA login failure error 18456:

Frequent SA login failures occur when the authentication mode of SQL Server is changed form windows authentication to SQL Server authentication.
In such cases the following error occurs:
Login failed for user ‘sa’

Use the following script to enable SA login with a password:

ALTER LOGIN sa ENABLE
GO
--Change the newpassword value below
ALTER LOGIN sa WITH PASSWORD = 'newpassword'
GO



Following are the error and error states:

error 18456 severity 14 state 1
error 18456 severity 14 state 2
error 18456 severity 14 state 5
error 18456 severity 14 state 6
error 18456 severity 14 state 7
error 18456 severity 14 state 38
error 18456 severity 14 state 8
error 18456 severity 14 state 9
error 18456 severity 14 state 11
error 18456 severity 14 state 12
error 18456 severity 14 state 28
error 18456 severity 14 state 38

Complete log of the error message in ssms:

sql server error 18456


Login failed for user 'username'.






Complete error log would look like this:


===================================

Cannot connect to servername.

===================================

Login failed for user 'username'. (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

------------------------------
Server Name: servername
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536


------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()



References: MSDN.

sql server error 26

$
0
0

microsoft sql server error 26 – Error Locating Server/Instance Specified

This is an instance specific error.This error does not Occur for default instances.This occurs mainly as a result of missing responce from the sql server browser service.

When you try to connect to an instance of SQL Server then you get the following error:

Cannot connect to SERVER\INSTANCE.


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (.Net SqlClient Data Provider)

Additional information would be as follows:
Error Number: -1
Severity: 20
State: 0

The following post helps you understand the basic reasons for network related errors in sql server Causes For Network Related Errors in SQL Server

Fix for this error:

  • Check and confirm if the server name is correct, Contact the server admin to validate this
  • Check and confirm if the instance name is correct, Contact the server admin to validate this
  • Add port number to the sql server instance name, Contact admin for the prot number of the instance
  • Ping the server and check if the server is up and running
  • Contact the admin of the server for additional help on this error

If you are the admin of the server on which the instance is running then

  • Check if the SQL Browser service is running on the server.
  • Give the browser service necessary permissions by giving it a logon account for running the service.
    Following are the minimum necessary permissions for the account:

    - Should have permission to log on as a service

    - Should have permissions to read and write the SQL Server registry keys, in order to fetch the port details etc.

    Also this security context of this account should be of a low privileged user, this minimizes exposure to attacks through the network.
  • Check if the instance is not hidden
  • Add exception to the sql browser service and sql server service in the firewall
  • Try connecting to the instance from the server using SSMS, if it is connecting then try connecting to the same instance from some other machine in the same doman
  • If you have portqry in the system then you can use the following command to query the port of the server.
    portqry -n SERVERNAME -p UDP -e 1434
    portqry can be downloaded from
    PortQry Command Line Port Scanner Version 2.0

Complete error in SQL Server Management Studio – SSMS:

===================================

Cannot connect to SERVERNAME\INSTANCENAME.

===================================

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476

------------------------------
Error Number: -1
Severity: 20
State: 0


------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectorThread()

References: MSDN

search references:
sql error 26
sql server error 26 error locating server instance specified
sql server 2008 error 26 error locating server instance specified
sql server 2005 error 26 error locating server instance specified
sql network interfaces error 26 error locating server instance specified
sharepoint 2010 provider sql network interfaces error 26 error locating server instance specified
sharepoint provider sql network interfaces error 26 error locating server instance specified
error 26 sql server express
sql error 26 connection
sql error 26 cannot connect
sql error 26 install
sql network interfaces error 26
host error 26
error 26 connecting sql server 2005
error 26 error locating server
error 26 locating server instance
sql server error 26
sql server error 26 firewall
sql server error 26 2008

SQL Server Error Messages List

$
0
0

SQL Server error messages can be found in sysmessages table in the master database.
Following are the columns of sysmessages table.

Column_name Type
error int
severity tinyint
dlevel smallint
description nvarchar
msglangid smallint

Following pages that contain list of sql server error messages.


restore higher version database backup on lower version sql server – restore problem

$
0
0

when you try to resore higher version database backup of sql server on a lower version of sql server you get an error:

The database was backed up on a server running version 10.50.1600. That version is incompatible with this server, which is running version 10.00.1600. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

10.50.1600 is of higher verion then 10.00.1600.
Also you can get the same error with different versions where higher version is being restored on a lower version database server

This database restore compatability error occurs because you are trying to restore higher version on lower version.

Why this error: Database servers get changed with service packs and new releases. New object types get added and the lower versions cannot understand these object types.
Example: Common Table Expressions used SQL Server 2008 will be unknown for SQL Server 2000.
In order to avoid such conflicts and problems – Higher end database restorations cannot be performed directly on lower end database servers. It is also not possible to Attach the higher version database to lower version sql server.

Following link helps you identify the database backup version Identify SQL Server Database Backup Version

How to restore such databases?

The best way to do restoration is to upgrade the lower version SQL Server to the version greater than or equal to the higher version SQL Server.

There is no direct way to restore the database with out upgrading the server,In such a case following are the alternate ways to restore.

Alternate ways to restore higher database versions on lower version sql servers:

Script the database Objects and restore them on the server
To script the database objects you can use Generate Scripts Task.
Generate Scripts Task can be found in SQL Server management studio.
RightClick on the database -> Click On Tasks -> Then Click on Generate Scripts…
Run through the wizard.
In the set scripting options tab in the generate scripts wizard click on advanced and select the following options:
For ‘types of data to script’ option Select ‘Schema and data’
For ‘Script for version’ select the required target SQL Server version

Generate the scripts and run the generated scripts on the destination server.

You may have to run the script multile times when you face any error.
Create a new database every time you rerun the script.
Fix the errors that you may face due to order in which objects are created (or) data is inserted into tables different tables.


Use SQL Server Import Export Wizard to copy data from source server to destination server (only Data)
You can find Import Export Wizard in SQL Server management studio.

On the Destination Server (Lower database version server)
RightClick on the database -> Click On Tasks -> Then Click on Import.
Give the correct source and destination servers and select all tables.
This creates an SSIS package and select the option to run immedietly if you want to copy data immedietly.


Copy data to destination tables using BCP (only Data)
You can also use BCP to copy data from source server to destination server.
BCP out tables on source server and BCP in on the destination server.


Note: The above methods do not guarantee the similarity between the two databases.



SQL Server Versions:

11.00.1750 11.00.1440 11.00.1103 10.50.2789 10.50.2776 10.50.2772 10.50.2769 10.50.2500 10.50.1807 10.50.1804 10.50.1800 10.50.1797 10.50.1790 10.50.1777 10.50.1769 10.50.1765 10.50.1753 10.50.1746 10.50.1734 10.50.1720 10.50.1702 10.50.1617 10.50.1600 10.50.1352 10.50.1092 10.00.5768 10.00.5766 10.00.5500 10.00.5416 10.00.4323 10.00.4321 10.00.4316 10.00.4285 10.00.4279 10.00.4272 10.00.4266 10.00.4000 10.00.3798 10.00.2850 10.00.2847 10.00.2821 10.00.2816 10.00.2808 10.00.2804 10.00.2799 10.00.2789 10.00.2787 10.00.2775 10.00.2766 10.00.2757 10.00.2746 10.00.2740 10.00.2734 10.00.2723 10.00.2714 10.00.2712 10.00.2710 10.00.2573 10.00.2531 10.00.2520 10.00.1835 10.00.1828 10.00.1823 10.00.1818 10.00.1812 10.00.1806 10.00.1798 10.00.1787 10.00.1779 10.00.1771 10.00.1763 10.00.1750 10.00.1600 10.00.1442 10.00.1300 10.00.1075 10.00.1049 10.00.1019 9.00.5266 9.00.5259 9.00.5254 9.00.5057 9.00.5000 9.00.4912 9.00.4325 9.00.4317 9.00.4315 9.00.4311 9.00.4309 9.00.4305 9.00.4294 9.00.4285 9.00.4273 9.00.4268 9.00.4266 9.00.4262 9.00.4230 9.00.4226 9.00.4224 9.00.4220 9.00.4216 9.00.4211 9.00.4207 9.00.4053 9.00.4035 9.00.4028 9.00.3356 9.00.3355 9.00.3353 9.00.3330 9.00.3328 9.00.3325 9.00.3320 9.00.3318 9.00.3315 9.00.3310 9.00.3301 9.00.3294 9.00.3282 9.00.3260 9.00.3259 9.00.3259 9.00.3257 9.00.3246 9.00.3244 9.00.3240 9.00.3239 9.00.3232 9.00.3231 9.00.3231 9.00.3230 9.00.3228 9.00.3224 9.00.3221 9.00.3221 9.00.3221 9.00.3221 9.00.3215 9.00.3208 9.00.3206 9.00.3200 9.00.3194 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3186 9.00.3182 9.00.3179 9.00.3178 9.00.3177 9.00.3177 9.00.3177 9.00.3175 9.00.3175 9.00.3175 9.00.3175 9.00.3175 9.00.3171 9.00.3169 9.00.3169 9.00.3166 9.00.3166 9.00.3161 9.00.3161 9.00.3161 9.00.3161 9.00.3159 9.00.3156 9.00.3155 9.00.3155 9.00.3155 9.00.3155 9.00.3154 9.00.3154 9.00.3154 9.00.3153 9.00.3152 9.00.3080 9.00.3077 9.00.3073 9.00.3068 9.00.3054 9.00.3050 9.00.3042 9.00.3033 9.00.3027 9.00.3026 9.00.2239 9.00.2237 9.00.2236 9.00.2236 9.00.2234 9.00.2233 9.00.2233 9.00.2233 9.00.2232 9.00.2231 9.00.2230 9.00.2229 9.00.2227 9.00.2226 9.00.2226 9.00.2223 9.00.2221 9.00.2219 9.00.2218 9.00.2216 9.00.2214 9.00.2214 9.00.2211 9.00.2211 9.00.2209 9.00.2208 9.00.2207 9.00.2207 9.00.2207 9.00.2206 9.00.2206 9.00.2206 9.00.2206 9.00.2202 9.00.2201 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2198 9.00.2196 9.00.2196 9.00.2195 9.00.2194 9.00.2192 9.00.2192 9.00.2191 9.00.2190 9.00.2189 9.00.2187 9.00.2181 9.00.2181 9.00.2176 9.00.2176 9.00.2175 9.00.2175 9.00.2175 9.00.2175 9.00.2175 9.00.2174 9.00.2167 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2164 9.00.2156 9.00.2153 9.00.2153 9.00.2050 9.00.2047 9.00.2040 9.00.2029 9.00.1561 9.00.1558 9.00.1554 9.00.1551 9.00.1551 9.00.1550 9.00.1550 9.00.1547 9.00.1545 9.00.1541 9.00.1541 9.00.1539 9.00.1538 9.00.1536 9.00.1534 9.00.1533 9.00.1532 9.00.1531 9.00.1528 9.00.1528 9.00.1528 9.00.1528 9.00.1528 9.00.1519 9.00.1518 9.00.1518 9.00.1518 9.00.1514 9.00.1503 9.00.1502 9.00.1500 9.00.1406 9.00.1399 8.00.2283 8.00.2282 8.00.2279 8.00.2273 8.00.2271 8.00.2265 8.00.2253 8.00.2249 8.00.2248 8.00.2246 8.00.2245 8.00.2244 8.00.2242 8.00.2238 8.00.2236 8.00.2234 8.00.2232 8.00.2231 8.00.2229 8.00.2226 8.00.2226 8.00.2223 8.00.2223 8.00.2218 8.00.2217 8.00.2215 8.00.2215 8.00.2215 8.00.2215 8.00.2209 8.00.2207 8.00.2201 8.00.2199 8.00.2197 8.00.2197 8.00.2197 8.00.2196 8.00.2194 8.00.2194 8.00.2192 8.00.2191 8.00.2191 8.00.2189 8.00.2189 8.00.2187 8.00.2187 8.00.2187 8.00.2187 8.00.2180 8.00.2180 8.00.2175 8.00.2172 8.00.2171 8.00.2168 8.00.2166 8.00.2162 8.00.2159 8.00.2156 8.00.2151 8.00.2151 8.00.2148 8.00.2148 8.00.2148 8.00.2148 8.00.2148 8.00.2148 8.00.2148 8.00.2147 8.00.2145 8.00.2145 8.00.2055 8.00.2040 8.00.2039 8.00.2026 8.00.1547 8.00.1037 8.00.1036 8.00.1035 8.00.1034 8.00.1029 8.00.1027 8.00.1025 8.00.1025 8.00.1024 8.00.1021 8.00.1020 8.00.1019 8.00.1017 8.00.1014 8.00.1014 8.00.1013 8.00.1009 8.00.1007 8.00.1003 8.00.1001 8.00.1000 8.00.997 8.00.996 8.00.996 8.00.994 8.00.994 8.00.994 8.00.993 8.00.993 8.00.993 8.00.991 8.00.990 8.00.988 8.00.985 8.00.980 8.00.977 8.00.973 8.00.972 8.00.970 8.00.967 8.00.962 8.00.961 8.00.959 8.00.957 8.00.955 8.00.954 8.00.952 8.00.952 8.00.952 8.00.949 8.00.948 8.00.944 8.00.937 8.00.936 8.00.935 8.00.934 8.00.933 8.00.929 8.00.928 8.00.927 8.00.926 8.00.923 8.00.922 8.00.919 8.00.916 8.00.915 8.00.913 8.00.911 8.00.910 8.00.908 8.00.904 8.00.892 8.00.891 8.00.879 8.00.878 8.00.876 8.00.876 8.00.876 8.00.873 8.00.871 8.00.871 8.00.870 8.00.869 8.00.866 8.00.865 8.00.865 8.00.863 8.00.863 8.00.859 8.00.858 8.00.857 8.00.857 8.00.857 8.00.856 8.00.854 8.00.852 8.00.852 8.00.851 8.00.850 8.00.850 8.00.850 8.00.848 8.00.847 8.00.845 8.00.845 8.00.844 8.00.842 8.00.841 8.00.840 8.00.840 8.00.839 8.00.839 8.00.837 8.00.837 8.00.837 8.00.837 8.00.837 8.00.819 8.00.818 8.00.818 8.00.818 8.00.818 8.00.818 8.00.816 8.00.814 8.00.811 8.00.811 8.00.811 8.00.807 8.00.804 8.00.801 8.00.800 8.00.800 8.00.800 8.00.798 8.00.794 8.00.794 8.00.794 8.00.794 8.00.791 8.00.790 8.00.789 8.00.788 8.00.781 8.00.780 8.00.780 8.00.780 8.00.779 8.00.776 8.00.775 8.00.769 8.00.769 8.00.765 8.00.765 8.00.765 8.00.765 8.00.763 8.00.762 8.00.760 8.00.743 8.00.743 8.00.741 8.00.736 8.00.735 8.00.733 8.00.730 8.00.728 8.00.725 8.00.725 8.00.723 8.00.721 8.00.721 8.00.718 8.00.715 8.00.715 8.00.714 8.00.713 8.00.710 8.00.705 8.00.703 8.00.702 8.00.701 8.00.701 8.00.700 8.00.696 8.00.696 8.00.695 8.00.695 8.00.695 8.00.693 8.00.690 8.00.689 8.00.688 8.00.686 8.00.682 8.00.679 8.00.678 8.00.667 8.00.665 8.00.661 8.00.655 8.00.652 8.00.650 8.00.644 8.00.608 8.00.604 8.00.599 8.00.594 8.00.584 8.00.578 8.00.578 8.00.561 8.00.558 8.00.558 8.00.552 8.00.552 8.00.534 8.00.532 8.00.475 8.00.474 8.00.473 8.00.471 8.00.469 8.00.452 8.00.444 8.00.444 8.00.443 8.00.428 8.00.384 8.00.296 8.00.287 8.00.251 8.00.250 8.00.249 8.00.239 8.00.233 8.00.231 8.00.226 8.00.225 8.00.223 8.00.222 8.00.218 8.00.217 8.00.211 8.00.210 8.00.205 8.00.204 8.00.194 8.00.190 8.00.100 8.00.078 8.00.047 7.00.1149 7.00.1143 7.00.1143 7.00.1097 7.00.1094 7.00.1094 7.00.1092 7.00.1087 7.00.1079 7.00.1078 7.00.1077 7.00.1063 7.00.1033 7.00.1026 7.00.1004 7.00.996 7.00.978 7.00.977 7.00.970 7.00.970 7.00.961 7.00.921 7.00.919 7.00.918 7.00.917 7.00.910 7.00.905 7.00.889 7.00.879 7.00.857 7.00.843 7.00.842 7.00.839 7.00.835 7.00.776 7.00.770 7.00.745 7.00.722 7.00.699 7.00.689 7.00.677 7.00.662 7.00.658 7.00.657 7.00.643 7.00.623 7.00.583 7.00.517

SQL Server Peculiar Issue – Error Converting Varchar to Bigint

$
0
0

Yesterday I had a chat with one of my friend who was having problem with his SQL Query.
Ill just list down his Peculiar problem and the way we solved it in this blog post. It would be a good learning to all.

The problem he had:
- There was an insert script for a table(say it tablex).
- All the columns in this table were of type varchar(100).
- This insert script was running fine for most of the insert values, but was failing when one of the column has value ’123E99′.
– The error the script was giving was:

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to bigint.

All the columns being varchar, why was this error occuring?
Why is this datatype conversion happening?
Is this conversion implicitly happening or it explicitly done?
Why was this error occuring only for value ’123E99′ but not for value ’128M99′?

Following are the steps we followed to find the reason for this error:
Checked the table definition to see if there were any triggers on the table.
There were no triggers on this table

Analysed the input value which was giving the error.
’123E99′ – This value has E as part of it.
When the below query is executed it gives 1 as output.

SELECT isnumeric('123E99');

But the output will be 0 for ’128M99′.
This means sql server understands ’123E99′ as a numeric value but not ’128M99′.

So there is some part of code somewhere in the database which is causing this issue by validating weather the value is numeric.

So we went ahead and searched for all the indexed views in the database.
We found one that is using this table.

Below is the piece of code in this indexed view

CASE WHEN ISNUMERIC(tablex.column2) = 1   
THEN CONVERT(BIGINT,tablex.column2) 

So this is the code that is giving the above error.
The ISNUMERIC is giving true but conversion to big int is failing as the value is larger that that of bigint.
Modifying this piece of code solved the issue. :)

Why was this indexed view code running when he was executing the insert script on tablex?

Just Because tablex is being used in the indexed view, indexed view has to be indexed with new data in tablex

Learnings form this post:
When you face such peculiar issues of conversion etc..

  • check for the design of the table and see if the conversion is implicitly happening.
  • Check for the triggers on the table, and see if there is any implicit or explicit datatype conversion happening there.
  • Check for the indexed views in the database, See if there is any implicit or explicit datatype conversion in the indexed views.

Verify SQL Server Database Backup

$
0
0

Today I wanted to share on this blog a simple but yet very powerfull SQL Server command RESTORE VERIFYONLY.

Syntax:

RESTORE VERIFYONLY FROM DISK = '<<location of database backup>>'

This command can be used to check weather your database backup is corrupted.

In order to explain this, I have taken backup of one of my database.
I also made another copy of database backup and I intentionally corrupted it.

DatabaseBackup.BAK is the perfect database backup.
DatabaseBackupCorrupted.BAK is the corrupted database backup.

So First I issued RESTORE VERIFYONLY command on the perferct database backup.
Following is the Query:

RESTORE VERIFYONLY FROM DISK = 'C:\DatabaseBackups\DatabaseBackup.BAK'

Output:
The backup set on file 1 is valid.

There were no errors and this made me confirm that the database backup is perfect.

Now I issued the same command on the corrupted database backup.

RESTORE VERIFYONLY FROM DISK = 'C:\DatabaseBackups\DatabaseBackupCorrupted.BAK'

As we expect the command errored out with the following error.

Output:

Msg 3242, Level 16, State 2, Line 1
The file on device ‘C:\DatabaseBackups\DatabaseBackupCorrupted.BAK’ is not a valid Microsoft Tape Format backup set.
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

There this error output confirms me that the database backup is corrupted.

When ever restoration of a database backup is failing we can use the RESTORE VERIFYONLY command on the back up set and verify it.

Note:
You get the error Operating system error 2(The system cannot find the file specified) when the file cannot be found on the file system. In order to fix it give the correct file name and file path.

Msg 3201, Level 16, State 2, Line 1 Cannot open backup device
‘C:\DatabaseBackups\DatabaseBackupCorrupted1.BAK’. Operating system error 2(The system cannot find the file specified.).
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

I got the above error when I issued the following command:

RESTORE VERIFYONLY FROM DISK = 'C:\DatabaseBackup.BAK'

As the file C:\DatabaseBackup.BAK does not exists.

Hope this posts helps!!!

Related post:
The media family on device is incorrectly formed. SQL Server cannot process this media family Error: 3241

Causes For Network Related Errors in SQL Server

$
0
0

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.

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

$
0
0

While using transactions in SQL Server sometimes you get the following errors:

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

Cause For this error:
There is no transaction in progress but the COMMIT/ROLLBACK TRANSACTION request is issued.

Replication of the scenario:

BEGIN TRAN
COMMIT TRAN
COMMIT TRAN

In the above query the first COMMIT TRAN statement has commited the transaction started by BEGIN TRAN, When the second COMMIT TRAN statement is executed the error The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION occurs.

Same is the case for ROLLBACK TRAN in the below query.

BEGIN TRAN
ROLLBACK TRAN
ROLLBACK TRAN 

Fix For this error:

As a best practice always check for open transactions before issuing COMMIT TRAN or ROLLBACK TRAN statement.
@@TRANCOUNT can be used to find the number of open transactions.

IF(@@TRANCOUNT>0)
COMMIT TRAN
IF(@@TRANCOUNT>0)
ROLLBACK TRAN

This way the commit/rollback tansaction error can be avoided.

Other Such Scenarios:

BEGIN TRAN
COMMIT  
COMMIT  
BEGIN TRAN
COMMIT WORK
COMMIT WORK
BEGIN TRAN
ROLLBACK WORK
ROLLBACK WORK

cannot drop database because it is currently in use

$
0
0

When you try to drop a database you get the below error:

Msg 3702, Level 16, State 3, Line 1
Cannot drop database “DataBaseName” because it is currently in use.

How to drop database when this error occurs?
1. Check if you are using the database you are trying to drop
– Close all the SQL Server management studio windows that are open
– Re-Connect to the server
– Try to drop the database.

2. Check if you are using the same database connection and trying to drop it.
– Change the database in the connection and try to run the drop statement.

Drop Database Using Same Database

3. Check if the script is trying to use the database that is to be dropped.

USE TestShrink
DROP DATABASE TestShrink

Change this to:

USE master
DROP DATABASE TestShrink

4. Kill all the sessions that are using the database you are trying to drop

EXEC sp_who2
--Run kill spid for each process that is using the database to be dropped.
kill <<processid>> -- Kill 57

Kill the sessions and try to drop the database.

MSG 1013 – The objects and in the FROM clause have the same exposed names

$
0
0

When you try to execute a SQL Query involving From clause you get the below error:

Msg 1013, Level 16, State 1, Line 1
The objects “Table1″ and “Table1″ in the FROM clause have the same exposed names. Use correlation names to distinguish them.

Reason for this error:
- Same table is used multiple times in the for clause with out using alias

CREATE TABLE Table1(A INT)
GO

SELECT * FROM Table1 join Table1 on Table1.A = Table1.A

Fix:
Give alias names for each table that is repeated in the query.

SELECT * FROM Table1 T1 join Table1 T2 on T1.A = T2.A

sql server cannot generate sspi context

$
0
0

fix for the error microsoft sql server cannot generate sspi context

1- Check if the system is up in the network. Telnet/Ping the server.
2- Check if the date/time match between the server and the client machines.
3- Change the service account of sqlserver and check if the error is resolved.
4- Refresh the dns on the client.
5- Check windows event log for advanced details of the error

Below links give additional details:

http://support.microsoft.com/kb/811889

http://support.microsoft.com/kb/319723

===================================

Cannot connect to server name.

===================================

Cannot generate SSPI context. (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=0&LinkId=20476

------------------------------
Server Name: server name
Error Number: 0
Severity: 11
State: 0
Procedure: GenClientContext


------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.SSPIError(String error, String procedure)
   at System.Data.SqlClient.TdsParser.SNISSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[] sendBuff, UInt32& sendLength)
   at System.Data.SqlClient.TdsParser.ProcessSSPI(Int32 receivedLength)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectorThread()

procedure has no parameters and arguments were supplied sql server

$
0
0

When you try to pass arguments to stored procedure which do not have parameters you get the below error:

Msg 8146, Level 16, State 1, Procedure sp_helpsort, Line 0
Procedure sp_helpsort has no parameters and arguments were supplied.

Sample:

EXEC sp_helpsort 'SQL_Latin1_General_Cp1_CS_AS_KI_WI'

Fix:

Remove parameters:

EXEC sp_helpsort

All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

$
0
0

Error:

Msg 205, Level 16, State 1, Line 1
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

Reason:
The select statements in the clause do not have the same number of columns.

Fix:
Make sure that all the starements using UNION, INTERSECT or EXCEPT operator have same number of expressions(columns).
Use column names instead of using * in the select list.

Sample example code

Before:

SELECT 1
UNION
SELECT 2,3

After:

SELECT 1,NULL
UNION
SELECT 2,3

Cannot use the ROW granularity hint on the table because locking at the specified granularity is inhibited.

$
0
0

Error:

Msg 651, Level 16, State 1, Line 1
Cannot use the ROW granularity hint on the table because locking at the specified granularity is inhibited.

This error could occur due to creation of indexes on the table with ALLOW_ROW_LOCKS = OFF

Check the indexes on the table to see if there is any index with ALLOW_ROW_LOCKS off.

Query:

SELECT * FROM sys.indexes 
WHERE  allow_row_locks = 0 and object_name(object_id) = [table name]

Replace the [table name] with the table name in the error and check if there are any indexes with allow_row_locks disabled.

Fix:
1. Disable the index or change the index to enable row locks.
2. Use page locks or table locks instead.

Cannot use the PAGE granularity hint on the table because locking at the specified granularity is inhibited.

$
0
0

Error:

Msg 651, Level 16, State 1, Line 1
Cannot use the PAGE granularity hint on the table [table name] because locking at the specified granularity is inhibited.

This error could occur due to creation of indexes on the table with ALLOW_PAGE_LOCKS = OFF

Check the indexes on the table to see if there is any index with ALLOW_PAGE_LOCKS off.

Query:

SELECT * FROM sys.indexes 
WHERE  ALLOW_PAGE_LOCKS = 0 and object_name(object_id) = [table name]

Replace the [table name] with the table name in the error and check if there are any indexes with ALLOW_PAGE_LOCKS disabled.

Fix:
1. Disable the index or change the index to enable page locks.
2. Use row locks or table locks instead.

Viewing all 74 articles
Browse latest View live