Pages

Monday, August 5, 2013

Is your software smart

There has been a lot of research on ontology and the semantic web has been in the news for quiet a while now.Its the next big thing in the future, making the web as intelligent as possible. I have been doing some research on this and I am not very sure if thats going to be true. Atleast not for all the products. Global gaints like Microsoft, Google etc can achieve a great success on intelligent tooling.

There are few projects where I worked and we developed million dollar tools with all the intelligent functionalities but simply wouldn't be successful. We did a lot of brain storming and found out that the clients were not willing to use it.The reason was that they didnt want to make their resources feel bad. The client said to use to make suggestions, not to validate or say that the analysis or the data their resources had collected was not just correct. Another important reason why intelligent tooling will not work is that the users wont understand the tool at all and any failures they just blame it on the software. "The software is not correct" thats what they say. Its true that people dont like to be said that they are wrong that too by a software.

In my view a software success  just doesn't depend on how intelligent you have made it but how much its accepted in the user community. Big software giants like Microsoft,Google can try these options but for companies which are not reputed will have tough time convincing their clients to try their software.

On the contrary intelligent tooling empowers software to be more powerful and cutting edge than it is now.

It will take still some time for the intelligent tools to come into lime light. As of now the developers have to be happy in building applications or products just to do some trivial tasks. Typically thats the mind set right now we have on softwares. It has to be still seen whether intelligent tooling will be success.As of  now I leave it for the time to tell.

Saturday, August 3, 2013

setting the TCP Port using WMI or using regsitry in C#


The TCP port is already enabled during the installation using the parameter TCPENABLED="1” in the SQLDemoConfig.ini file in silent Installation.Once the installation is complete we will change the TCP Port number using Windows Management Instrumentation (WMI). The WMI does not work on the Default SQL Instance it only works on the Instance we have installed. If we try it on the default instance we will get a “Alter() failed” error. One more reason why you may get “Alter() failed” is the Visual Studio is not run in administrator mode. Right click and “Run as administrator”.


The following references should be added to your Project/Solution.
 

1.    Microsoft.SqlServer.ConnectionInfo.dll

2.    Microsoft.SqlServer.Management.Sdk.Sfc.dll

3.    Microsoft.SqlServer.Smo.dll

4.    Microsoft.SqlServer.SmoExtended.dll

5.    Microsoft.SqlServer.SqlWmiManagement.dll


Use the Namespaces as below
 

using System.ServiceProcess;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Management.Smo.Wmi;
using System.Diagnostics;

 

The code to update the TCP Port number using WMI is as follows:-

  

ManagedComputer mg = new ManagedComputer();
 
//Get the service by service name
ServiceController service = new ServiceController("MSSQL$DEMOSQLEXP");
 
//Stop the service if its running
if (service.Status == ServiceControllerStatus.Running)
{
     service.Stop();
}
 
//Get the SQLEXPRESS instance
ServerInstance serverInstance = mg.ServerInstances["DEMOSQLEXP"];
ServerProtocolCollection prot = serverInstance.ServerProtocols;
ServerProtocol serverProtocol = serverInstance.ServerProtocols["Tcp"];
//Change the TCP port number to 1433 or desired port
serverProtocol.IPAddresses["IPALL"].IPAddressProperties["TcpPort"].Value = "1433";
 
//Change the TCP Dynamic port number to blank             serverProtocol.IPAddresses["IPALL"].IPAddressProperties["TcpDynamicPorts"].Value = String.Empty;
 
 
//Commit the changes
serverProtocol.Alter();
 
 
//Start the service which is already stopped
if (service.Status == ServiceControllerStatus.Stopped)
{
     service.Start();
}
 

 
It is important that we stop the service before making the changes and start the service once the change is done as the changes won’t take effect unless we restart the service. That is the reason we are using the ServiceController class.

There is one more way to enable the TCP Port and update TCP Port number is to write the Registry entry but that approach is not recommended.

The code to update the TCP port number is as follows:-

string keyNameTcp = @"SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp";
                  
string keyNameTcpIP = @"SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp\IPAll";
 
 
RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                  
RegistryKey subkeyTcp = Registry.LocalMachine.OpenSubKey(keyNameTcp, true);
 
subkeyTcp.SetValue("Enabled", "00000002", RegistryValueKind.DWord);
subkeyTcp.Close();
 
RegistryKey subkeyTcpIP = Registry.LocalMachine.OpenSubKey(keyNameTcpIP, true);
subkeyTcpIP.SetValue("TcpPort", "1433");
subkeyTcpIP.Close();
 

 

 

Integrating the silent or unattended installation of SQL Server 2008 R2 in the C# code base


The code to integrate the silent installation in to the C# code base is very simple. We will start the process of setup and attach the arguments which are required. The code to do so is as follows:-

 
//Creating a process to do the silent installation
Process p = new Process();
 
//File names and File Path along with the process arguments
p.StartInfo.FileName = @"C:\DemoSetup\SQLEXPRWT_x86_ENU.exe";
p.StartInfo.Arguments = @"/q /ConfigurationFile=C:\DemoSetup\SQLDemoConfig.ini";
 
p.StartInfo.UseShellExecute = false;
p.Start();
 
//Waiting for the process to complete
p.WaitForExit();
 

 

Note:- To know the contents of the SQLDemoConfig.ini file please refer my earlier blogs.

This step p.WaitForExit(); is very important because we need to wait till the sql server installation is complete before setting the TCP port otherwise as there is no sql server and the service is not available an exception is thrown.