Search

Thursday, February 18, 2016

Query to get IP address of SQL Server

Use below query to get IP address of SQL Server:

DECLARE @IP varchar(40)
DECLARE @IPLine varchar(200)
DECLARE @Pos int

SET NoCount ON
SET @IP = NULL

Create Table #Temp (IPLine VarChar(200))
INSERT #temp EXEC master..xp_cmdshell 'IPconfig'

SELECT TOP 1 @IPLine = IPLine FROM #Temp
WHERE Upper (IPLine) LIKE '%IP ADDRESS%' OR Upper (IPLine) LIKE '%IPV4 ADDRESS%' 
    IF (ISNULL (@IPLine,'***') != '***')
      BEGIN 
       SET @Pos = CharIndex (':',@IPLine,1);
       SET @IP = LTrim(RTrim(SubString (@IPLine , @Pos + 1 ,len (@IPLine) - @Pos)))
      END 
PRINT @IP
DROP TABLE #temp
SET NoCount OFF

If you get below error after executing above query:

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
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.

Than you had to enable xp_cmdshell in surface area configuration. and than rerun the above query.

Monday, February 8, 2016

How to show backup or restore progress to user in a progressbar?

You can show backup or restore progress to user in a progress bar if you had installed 

sp_who2k5 

into your master database. You have to run the below command:

sp_who2k5 1, 1

The result will include all active transaction. Search the backup in the requestCommand field. The aptly named percentComplete field will give you the progress of the backup. 

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.