Mar 2, 2010

Start, Stop, Pause, Resume a service

Read this article to load a service : http://angeldeeps.blogspot.com/2010/03/load-list-of-services.html

private void cmdStartService_Click(object sender, System.EventArgs e)
{
try
{
msvc.Start();
fUpdatingUI = true;
UpdateUIForSelectedService();
fUpdatingUI = false;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cmdResumeService_Click(object sender, System.EventArgs e)
{
try
{
msvc.Continue();
fUpdatingUI = true;
UpdateUIForSelectedService();
fUpdatingUI = false;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cmdPauseService_Click(object sender, System.EventArgs e)
{
try
{
msvc.Pause();
fUpdatingUI = true;
UpdateUIForSelectedService();
fUpdatingUI = false;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cmdStopService_Click(object sender, System.EventArgs e)
{
try
{
msvc.Stop();
fUpdatingUI = true;
UpdateUIForSelectedService();
fUpdatingUI = false;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void UpdateUIForSelectedService()
{
// Update the command buttons for the selected service.
string strName;
int ItemIndex;
try
{
if (this.lvServices.SelectedItems.Count == 1)
{
strName = this.lvServices.SelectedItems[0].SubItems[0].Text;
ItemIndex = this.lvServices.FocusedItem.Index;
msvc = ((ServiceController) (mcolSvcs[strName]) );
// if it's stopped, we should be able to start it
this.cmdStart.Enabled = (msvc.Status == ServiceControllerStatus.Stopped);
// Check if we're allowed to try and stop it and make sure it's not already stopped.
this.cmdStop.Enabled = (msvc.CanStop && (!(msvc.Status == ServiceControllerStatus.Stopped)));
// Check if we're allowed to pause it and see if it is not paused already.
this.cmdPause.Enabled = (msvc.CanPauseAndContinue && (!(msvc.Status == ServiceControllerStatus.Paused)));
// if it's paused, we must be able to resume it.
this.cmdResume.Enabled = (msvc.Status == ServiceControllerStatus.Paused);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Populate list from untyped DataSet

A table in a dataset is used to populate a list box with employee name from the employee table. With the dataset the name of the table and field must be known at design time. if they are misspelled or mistyped an error will be generated only at runtime.

Define the dataset.

private DataSet dsEmp;


//Call this on your button click event
PopulateListFromDS();


private void PopulateListFromDS()

{

string s;

int i;

//Clear items in ListBox

lstResults.Items.Clear();



for(i=0; i <=dsEmp.Tables["EmplyeeDS"].Rows.Count - 1; i++)

{

// Check to see if row is flagged deleted.

if (dsEmp.Tables["EmplyeeDS"].Rows.RowState != DataRowState.Deleted)

{

// Get the product name for each record.

s = dsEmp.Tables["EmplyeeDS"].Rows["EmpName"].ToString();

// Add product name to the list box

lstResults.Items.Add(s);

}

}

}

Spool Command in Oracle

Spool [pathdirectory]

Spool will record all your statements in a text file which will be created in the path specified by you in pathdirectory.

Until and unless you swtich off the spool it won't record your statements but a file will be created in that path.

For example, I write


SQL> spool C:\temp.txt (temp file will be created in C drive)

SQL> select * from tablename1 (Output will be generated)

SQL> select * from tablename2 (Output will be generated)

etc...

SQL> spool off (All records after your file was created will be recorded with errors/messages/outputs/results etc.)


You can try doing this using SQL * Plus Prompt

Load list of services

This code will load a list of all Services

private ServiceController msvc;
private ListViewItem ViewItem;
private Hashtable mcolSvcs = new Hashtable();
private bool fUpdatingUI ;

private void frmMain_Load(object sender, System.EventArgs e)
{
EnumServices();
}

private void EnumServices()
{
// Get the list of available services and load the list view control with the information
try
{
fUpdatingUI = true;
this.lvServices.Items.Clear();
if (!(mcolSvcs == null))
{
mcolSvcs = new Hashtable();
}
ServiceController[] svcs = ServiceController.GetServices();
foreach(ServiceController svc in svcs)
{
ViewItem = this.lvServices.Items.Add(svc.DisplayName);
ViewItem.SubItems.Add(svc.Status.ToString());
ViewItem.SubItems.Add(svc.ServiceType.ToString());
mcolSvcs.Add(svc.DisplayName,svc);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
fUpdatingUI = false;
}
}

Concatenation operator in Oracle

The concatenation operator will concatenate columns or character strings to other columns. Represented by two vertical bars (||).

For example,
SELECT lastname||jobcode as "Employees" FROM tblEmployee;

It will result as
Employees

xyz_VP

abc_PRES

pqr_VP
Bookmark and Share