Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Problem with changing SQL Server settings by WMI

$
0
0

Hi

I am using WMI in order to change sql server 2012 properties with use of .NET framework windows application written in c# on OS Windows Server 2012 Standard.
My code:
                ManagementScope mScope = new ManagementScope(@"\root\Microsoft\SqlServer\ComputerManagement11");
                mScope.Connect();
                richTextBox1.AppendText(mScope.Path.Path + "\r\n");
                ObjectQuery oQuery = new ObjectQuery(@"select * from ServerNetworkProtocolProperty where InstanceName='AVSEXPRESS' and ProtocolName='Tcp' and IPAddressName='IPAll'");
                richTextBox1.AppendText(oQuery.QueryString + "\r\n");
                ManagementObjectSearcher mos = new ManagementObjectSearcher(mScope, oQuery);
                richTextBox1.AppendText("object searcher" + "\r\n");
                ManagementObjectCollection returncollection = mos.Get();
                richTextBox1.AppendText("Count: " + returncollection.Count + "\r\n");
                foreach (ManagementObject mo in returncollection)
                {
                    mo["TcpPort"] = "12345";
                    richTextBox1.AppendText("tcp port set" + "\r\n");
                    mo["TcpDynamicPorts"] = string.Empty;
                    richTextBox1.AppendText("tcp dynamic ports set" + "\r\n");
                }
               
I have checked already with use of WBEMTest Utility if namespace I specified was correct and my Query works. With use of that tool I am able to obtain data I was looking for. My problm is that when I do the same with code presented above in line

ManagementObjectCollection returncollection = mos.Get();

when executing Get() method I get an exception with an empty message.
Is there any way to fix that ? I am sure that my scope and query are correct.

Regards


kicaj


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>