Search

Monday, February 1, 2016

The SQL Server system configuration checker cannot be executed due to WMI configuration on the machine.

Last week I got below error in clients system:

The SQL Server system configuration checker cannot be executed due to WMI configuration on the machine. Error 2147749896

The main cause of the problem are:

Unfinished SQL Server components may be present.
Components or files related to WMI service might be unregistered or missing.
Microsoft Data Access Components may not be installed.
The problem was that the WMI repository is corrupted. Reinstall the WMI.

Solution:
Check the version of MDAC you have installed. SQL Server will require MDAC 2.8 or higher. To check MDAC:
Click Start / Run. Type regedit. Click OK.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DataAccess
Note the Registry Key for Version. If less than 2.8.xxxx,
download and install the latest MDAC 2.8 version.

Monday, January 11, 2016

Error: 64, connection was successfully established with the server, but then an error occurred during the pre-login handshake.

I had got below error in my friend's system:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 – The specified network name is no longer available.) (Microsoft SQL Server, Error: 64)

I googled this error and got mixed results and solutions but none solved my problem.


After some more googling I found below solution that worked for me.
The solution is:
Go to the MSSQL Configuration Manager and expand the SQL Network Configuration and click on the PROTOCOLS node. Right click on TCP/IP and open up the PROPERTIES panel and Select the IP ADDRESS tab.
Check the IP ADDRESS field's value are correct and match the system it is running on.
Restart the service, and the problem is solved.
Make sure you fill in the TCP PORT, even if you are using the default 1433.

Monday, January 4, 2016

Error occurred during database creation

Sometime when you create a new database by using CREATE Database statement in SSMS (SQL Server Management Studio), you may got below error message and you are not able to create Database:

Server: Msg 5105, Level 16, State 2, Line 1
Device activation error. The physical file name '' may be incorrect.

Server: Msg 1802, Level 16, State 1, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check previous errors. 

The main reason of above error is path of folder store in the registry values does not exist. When the path of folder is incorrect then MS SQL server throws above error messages.

You can fix the error by using SSMS. SSMS is able to set the default directory value for Data and log Files. Follow below steps to change the default value: 


  • Start SQL server Management Studio.
  • In Management Studio, right click on your instance and select properties
  • In properties, click on the database setting option.
  • Now go to the new database default location section
  • Correct folder path from default directory box and default log directory box
  • Press OK
  • Stop the instance of MS SQL database
  • Restart the instance of MS SQL server database.

Monday, November 2, 2015

List database objects modified in the last ‘X’ days

Use below query to get the list of databases modified in last 'X' days:

USE <database_Name>; 
GO 
SELECT Name AS object_Name,  
  Create_Date, Modify_Date, 
  Type_Desc,
  SCHEMA_Name(Schema_ID) AS Schema_Name 
FROM sys.Objects 
WHERE Modify_Date > GETDate() - <X_Days> 
ORDER BY Modify_Date; 
GO 

Notes: Replace <database_Name> with Database Name and <X_Days>  with No of days.

Monday, September 14, 2015

Weekend count between two dates

Use below query to find the weekend count between two dates:

DECLARE @DateFrom DateTime, @DateTo DateTime, @Total int, @Number int, @Counter int
SELECT @DateTo = GetDate(), @DateFrom = GetDate() - 22, @Total = DateDiff(dd, @DateFrom, @DateTo), @Number = 1, @Counter = 0
WHILE (@Number <= @Total)
BEGIN
IF DatePart(dw, @DateFrom) = 1 OR DatePart(dw, @DateFrom) = 7
BEGIN
SET @Counter = @Counter +1
END
SET @DateFrom = @DateFrom+1
SET @Number = @Number + 1
END
PRINT @Counter