VBScript Error Trying to disable dynamic port in SQL Server

1

I've been trying to automate disabling dynamic ports in a new installation of SQL Server 2012 and setting a static TCP port. I can do this without an issue from the SQL Configuration Manager, but getting a script to do this is giving me more trouble. Luckily, I found someone that was looking to do the exact same thing here: MSDN Forums.

The code I'm using is the following:

Private Function setProperty ( ByVal path, ByVal value )
    Set obj = GetObject(path)
    errornumber = obj.SetStringValue(value)
    If Not errornumber = 0 Then
        WScript.Quit(errornumber)
    End If
End Function

Set args = WScript.Arguments
If Not args.Count = 1 Then
    WScript.Echo "ERROR: Invalid arguments"
    WScript.Echo "Usage: cscript " & WScript.ScriptName & " "
    WScript.Quit(255)
End If

' set TCP/IP port of SQLServer instance 'SQLSERVER_MATRIX'
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpPort',PropertyType=1,ProtocolName='Tcp'", args(0)
' switch off dynamic ports
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpDynamicPorts',PropertyType=1,ProtocolName='Tcp'", ""

I try running it as suggested on the site with

cscript.exe //nologo set_port_property.vbs

and get the error:

set_port_property.vbs(1,1) (null): 0x8004100E

So that's giving me a namespace error and this is where I'm stuck. It doesn't look like anyone else is having issues with this file as I've found it in multiple places, but I'm trying this on a Windows 10 computer with SQL Server 2012 and everything I found was using 2008 and at most Windows 8. There's a Scriptomatic 2.0 tool that may help, but the link on Microsoft's page is broken so I don't know where to go from here.

sql-server
vbscript
wmi
asked on Stack Overflow Feb 3, 2016 by gdawgrancid • edited Feb 17, 2016 by user692942

1 Answer

1

The error code as you point out is

WBEM_E_INVALID_NAMESPACE (0x8004100E)
The specified namespace did not exist on the server.

Which is pretty self explanatory, basically the namespace being passed is not recognised for whatever reason, usually it's just incorrectly typed but as you have already mentioned others are using this script without issue.

Couple of suggestions

  1. This likely points to the machine, the first thing I would try is running the script on another machine to see if it can be isolated to this machine alone.

  2. You may also want to test the health of the WMI installation using the in-built tools provided in Windows. The wbemtest.exe tool is a great little tool for testing connection to and query WMI respositories.


Stumbled on the Answer

In the process of answering this question think I may have stumbled on the answer.

Tried suggestion 2. myself to test connecting to

root\microsoft\sqlserver\computermanagement

but failed with the same error using wbemtest.exe but found I could connect to

root\microsoft\sqlserver

After a quick google found the MSDN documentation that describes"How to: Access WMI Provider for Configuration Management using WQL" pointed me in the right direction.

You see the namespaces are different for later versions of SQL Server.

After connecting to

root\Microsoft\SqlServer\ComputerManagement11

using wbemtest.exe I no longer received the error and was able to browse classes and instances.

With that in mind changing your namespace in the code should fix the issue.

' set TCP/IP port of SQLServer instance 'SQLSERVER_MATRIX'
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement11:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpPort',PropertyType=1,ProtocolName='Tcp'", args(0)
' switch off dynamic ports
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement11:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpDynamicPorts',PropertyType=1,ProtocolName='Tcp'", ""

In fact at the very bottom of that thread on MSDN someone even hints at this but for SQL Server 2008

Goozak posted in MSDN Forums - silent install with fixed tcp port
Date: Wednesday, March 17, 2010 3:13 PM


"know this is an old thread, but since this is the post I found that helped me solve my problem, I just want to add that for SQL Server 2008 Express, you need to use ComputerManagement10 :ServerNetworkProtocolProperty..."

answered on Stack Overflow Feb 17, 2016 by user692942 • edited Feb 17, 2016 by user692942

User contributions licensed under CC BY-SA 3.0