winhttp.winhttprequest.5.1 the server name or address could not be resolved

Problem: When using POST or GET with sp_OAMethod in SQL Server, you receive the following error:

Error Source Description
0x80072EE7 WinHttp.WinHttpRequest The server name or address could not be resolved 

An example of a HTTP Post function is provided below:

Create function GetHttp
(
    @url varchar(8000)      
)
returns varchar(8000)
as
BEGIN
    DECLARE @win int 
    DECLARE @hr  int 
    DECLARE @text varchar(8000)

    EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT 
    IF @hr <> 0 EXEC sp_OAGetErrorInfo @win

    EXEC @hr=sp_OAMethod @win, 'Open',NULL,'GET',@url,'false'
    IF @hr <> 0 EXEC sp_OAGetErrorInfo @win

    EXEC @hr=sp_OAMethod @win,'SEND'
    IF @hr <> 0 EXEC sp_OAGetErrorInfo @win

    EXEC @hr=sp_OAGetProperty @win,'ResponseText',@text OUTPUT
    IF @hr <> 0 EXEC sp_OAGetErrorInfo @win

    EXEC @hr=sp_OADestroy @win 
    IF @hr <> 0 EXEC sp_OAGetErrorInfo @win 
    
    RETURN @text
END

The function is then called with a URL Variable:

DECLARE @url VARCHAR(500)
SET @url = 'http://google.co.uk'
exec GetHttp @url

Although there are many reasons for the error, if the simpler solutions have not worked (eg: Making sure the URL is correct, that the DNS resolves, Firewall is correctly configured) then the issue may be a hidden proxy.

WinHTTP uses its own proxy and depending on how your servers are configured, it may need to be set or unset.

For me, the proxy was enabled and i needed direct access.

Open an Elavated Powershell window:

> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Proxy Server(s) :  proxy.xxxxxxxxx.co.uk:8080

    Bypass List     :  (none)

> netsh winhttp reset proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

Should I be using COM Objects post SQL 2000??!?

We did this for an old system, but my recommendation would be to use SQL Server CLR’s to access REST Services.

Great post here on MSDN of how to do this – http://blogs.msdn.com/b/sqllive/archive/2008/06/18/accessing-rest-based-web-services-using-sql-clr.aspx

Using DISM to enable features

From windows 2012, pkgmgr has been deprecated and cannot be used from the command line to install features on windows server.

Use the following instead to install a feature with a one line command:

dism /online /Enable-Feature /FeatureName:TelnetClient

Ive previously blogged about pkgmgr here – https://dbamohsin.wordpress.com/2013/07/05/pkgmgr-utility-to-install-windows-features-including-telnet/

Is my Windows OS 32-bit or 64-bit?

Cool little query to retrieve OS architecture version

wmic os get osarchitecture

Returns something like this:

H:0_ORA_SETUP\sql>wmic os get osarchitecture
OSArchitecture
64-bit

the wmic os get command has more variables to search on. eg:

H:0_ORA_SETUP\sql>WMIC OS GET osarchitecture, caption /value
Caption=Microsoft Windows 7 Enterprise
OSArchitecture=64-bit

A lot more commands available – http://ss64.com/nt/wmic.html

Get CPU/Core/HT Count

Several different methods available.

T-SQL:

SELECT 
  cpu_count AS NumberOfLogicalCPUs
, hyperthread_ratio
, ( cpu_count / hyperthread_ratio ) AS NumberOfPhysicalCPUs
, CASE
      WHEN hyperthread_ratio = cpu_count THEN cpu_count
      ELSE ( ( cpu_count - hyperthread_ratio ) / 
             ( cpu_count / hyperthread_ratio ) )
 END AS NumberOfCoresInEachCPU
, CASE
    WHEN hyperthread_ratio = cpu_count THEN cpu_count
    ELSE ( cpu_count / hyperthread_ratio ) 
    * ( ( cpu_count - hyperthread_ratio ) / 
            ( cpu_count / hyperthread_ratio ) )
  END AS TotalNumberOfCores
FROM sys.dm_os_sys_info

Powershell – Get Cores:

Get-WmiObject -namespace "root\CIMV2" -class Win32_Processor -Property NumberOfCores | select NumberOfCores

CMD Line:

wmic cpu get NumberofCores, NumberofLogicalProcessors

Useful Links:

http://weblogs.sqlteam.com/tarad/archive/2008/08/05/How-to-get-physical-CPU-count-on-a-server.aspx

http://www.pxserver.com/WinAudit.htm

Pkgmgr utility to install windows features including Telnet

Install Telnet Client by using a command line

On Windows 7, Windows Server 2008 R2, Windows Server 2008 or Windows Vista you can use the following command line procedure to install Telnet Client.

Open a command prompt window. Click Start, type cmd in the Start Search box, and then press ENTER.
Type the following command:

pkgmgr /iu:"TelnetClient"

If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue. When the command prompt appears again, the installation is complete.

http://technet.microsoft.com/en-us/library/cc771275(v=ws.10).aspx

Pkgmgr options:

http://technet.microsoft.com/en-us/library/cc749465(v=ws.10).aspx

Full list of windows server packages

http://technet.microsoft.com/en-us/library/cc748930(v=ws.10).aspx

View the members of an Active Directory group…Without being an Admin

From a computer that’s a member of the domain, open a command-prompt and run:

NET GROUP "group name" /DOMAIN

Unless your administrators have changed the permissions on the group object you will be able to view the membership that way.

You can use AD Users and Computers (dsa.msc) even if you’re not an administrator, but this, at least, can be done w/o installing anything.

Virtual Box Error Code 0xc0000225 when installing Windows Server 2012 VM

Got the following error when attempting to Install Windows Server 2012 in Virtual box:

Windows failed to start.
A recent hardware or software change might be the cause.
Status: 0xc0000225

Picture

To fix, Open the settings for the virtual machine:

System > Enable IO APIC

The following was taken from the Virtualbox manual, chapter 3:

In any host, you should enable the I/O APIC for virtual machines that you intend to use in 64-bit mode. This is especially true for 64-bit Windows VMs. See the section called “"Advanced" tab”. In addition, for 64-bit Windows guests, you should make sure that the VM uses the Intel networking device, since there is no 64-bit driver support for the AMD PCNet card; see the section called “Virtual networking hardware”.

I probably came across this issue because i select [Other Windows] as a template for creating my VM as Windows Server 2012 was not on the list, so none of the options were pre-selected.

Free eBooks from Microsoft

Came across this the other day – http://blogs.msdn.com/b/microsoft_press/archive/2012/05/04/free-ebooks-great-content-from-microsoft-press-that-won-t-cost-you-a-penny.aspx

Some great content :

image

Cluster log in Windows Server 2008

In Windows 2003, The cluster log could be access from C:\Windows\Cluster\Cluster.log.

In Windows 2008, the logging architecture has been replaced with a event based tracing system.

The Vista\Windows Server 2008 Event Model is the next generation of Windows Event Logging and replaces the current version of the Event Log shipped in Microsoft® Windows® 2003 Server, Microsoft® Windows® XP, Windows 2000, and previous versions of Microsoft® Windows NT®.

The new model is a major update to the NT Event Log service. It maintains 100% backwards compatibility with the existing APIs and functionality and fully leverages the existing NT Event Log instrumentation in the applications and services. At the same time, it eliminates some of the limitations of the NT Event Log and provides additional features to better support monitoring and diagnostics of Windows applications, services, components, and drivers.

To extract the Cluster log in WIndows 2008, do the following:

1. Open Cmd Prompt

2. Type the following command

Cluster /Cluster:yourclustername log /gen

image

The cluster log will be available in C:\Windows\Cluster\Reports

To send to a specific directory, for example C:\temp do:

Cluster /Cluster:yourclustername log /gen /copy:"C:\temp"

Brilliant in depth article on the cluster log here – http://blogs.technet.com/b/askcore/archive/2010/04/13/understanding-the-cluster-debug-log-in-2008.aspx