Mobile Management For SQL Server(s!) - Siccolo - SQL Management Tool

Siccolo Development Articles - WMI connections made easy in .NET - Windows Event Log Diagnostics and Managing Event Log with .NET, Web Development and Securing Web Applications and Web Services, Windows Mobile Development, .NET Software Development

How to add an event source
    By using System.Diagnostics namespace (that provides classes to interact with system processes, event logs, and performance counters) we have access to:
  • EventLog - functionality to write to event logs, read event log entries, and create and delete event logs and event sources on the network.
  • EventLogEntry - single record in the event log.
By using EventLog, we can interact with Windows event logs - access or customize Windows event logs, which record information about important software or hardware events.
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Dim objApplicationLog As EventLog
        Dim SourceName As String
        SourceName = txtSourceName.Text
        If SourceName = "" Then
            MessageBox.Show("Enter Event Source Name", _
                            "Add Event Source", _
                            MessageBoxButtons.OK, _
            Exit Sub
        End If

        objApplicationLog = New EventLog()

        If Not EventLog.SourceExists(SourceName) Then
            EventLog.CreateEventSource(SourceName, SourceName)

            objApplicationLog.Source = SourceName

            objApplicationLog.WriteEntry(SourceName, "Source Added...")

           MessageBox.Show("Event Source Name [" & SourceName & "] already exists!", _
                            "Add Event Source", _
                             MessageBoxButtons.OK, _
        End If

End Sub
  • EventLog.Source - Gets or sets the source name to register and use when writing to the event log.
  • EventLog.SourceExists() - Searches a computer's registry for a given event source - whether an event source is registered on the computer (local or remote).
  • EventLog.CreateEventSource() - Establishes an application as able to write event information to a particular log on the system.
    If you do not specify a log name when calling CreateEventSource(), your source will be registered to the Application log. If you specify the name of a log that does not exist, the system creates a custom event log for you and registers the Source to that log.
  • EventLog.WriteEntry() - Writes an entry in the event log.
    In this example, using objApplicationLog.WriteEntry(SourceName, "Source Added..."), application Writes an information type entry with the "Source Added..." message text to the event log, using SourceName as the specified registered event source.

How to write to Windows Event Log:

In this example, by using System.Diagnostics namespace, application can write to EventLog - generate entries in Windows Event Log.

Application can only receive event notifications when entries are written on the local computer and cannot receive notifications for entries written on remote computers.
When form loads, application populates list of available Windows Event Log names on a computer and Event Types:
        private void frmTestWatcher_Load(object sender, EventArgs e)
            //populate with event log names:
            foreach (EventLog eventLog in EventLog.GetEventLogs())
            { cboEventLogList.Items.Add(eventLog.Log ); }
..., then, upon user clicking on "Generate Entry" button:
	private void cmdGenerateEntry_Click(object sender, EventArgs e)
            //... check user input ... 

            //generate event:
            EventLog eventLog = new EventLog(cboEventLogList.Text);
            eventLog.Source = txtSourceName.Text;

            eventLog.WriteEntry(txtMessage.Text, ConvertEventType(cboEventTypeList.Text));

where ConvertEventType() function:
        private EventLogEntryType ConvertEventType(string eventType)
            switch (cboEventTypeList.Text)
                case "Information": return EventLogEntryType.Information; break;
                case "Error": return EventLogEntryType.Error; break;
                case "Warning": return EventLogEntryType.Warning; break;
            return EventLogEntryType.Information;


How to monitor and react to event log changes

In this example, by using System.Diagnostics namespace, application "attaches" itself to monitor for EventLog changes.
EventLog.EntryWritten event - Occurs when an entry is written to an event log on the local computer.
Application can only receive event notifications when entries are written on the local computer and cannot receive notifications for entries written on remote computers.
To get event notifications, application sets EnableRaisingEvents to true.
	    Private m_ApplicationLog As EventLog
            Private m_SystemLog As EventLog	
 	    m_ApplicationLog = New EventLog()
            m_ApplicationLog.Log = "Application"
            AddHandler m_ApplicationLog.EntryWritten, AddressOf ApplicationLog_OnEntryWritten
            m_ApplicationLog.EnableRaisingEvents = True

            m_SystemLog = New EventLog()
            m_SystemLog.Log = "System"
            AddHandler m_SystemLog.EntryWritten, AddressOf SystemLog_OnEntryWritten
            m_SystemLog.EnableRaisingEvents = True

    Public Sub ApplicationLog_OnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)

            '.... handle Application event log change

        Catch err As Exception

        End Try
    End Sub

    Public Sub SystemLog_OnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
              '.... handle System event log change
        Catch err As Exception

        End Try
    End Sub
AddHandler m_ApplicationLog.EntryWritten, AddressOf ApplicationLog_OnEntryWritten identifies the method that will handle the EventLog change event.
ApplicationLog_OnEntryWritten() - The event handler is called whenever the EventLog change event occurs.

How to check for Shared Open Files - WMI connections made easy in .NET - Get System Information Using WMI in .NET - NET Framework's Windows Management Instrumentation (WMI) services allows ...:
Win32_ConnectionShare class)
Using Computer Management management console:

Code bellow produces:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim query As ManagementObjectSearcher = _
                    New ManagementObjectSearcher(New SelectQuery("Win32_ConnectionShare"))

            Dim management_object As ManagementObject
            For Each management_object In query.Get()

                Dim objAntecedent As ManagementObject = _
                        New ManagementObject(management_object("Antecedent").ToString)

                Dim objDependent As ManagementObject = _
                            New ManagementObject(management_object("Dependent").ToString)

                MessageBox.Show(management_object("Antecedent") & vbCrLf & _
                                   management_object("Dependent") & vbCrLf & _
                                   "Open Files : [" & objDependent("NumberOfFiles").ToString & "]" & vbCrLf & _
                                   "Local Path : [" & objAntecedent("Path") & "]")

        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim objWindows As Object = GetObject("WinNT://./LanManServer")
        Dim objRsc As Object
        For Each objRsc In objWindows.Resources
    End Sub


How to enumerate running processes using WMI and Win32_Process class - WMI connections made easy in .NET - Get System Information Using WMI in .NET - NET Framework's Windows Management Instrumentation (WMI) services allows ...:
Using Win32_Process and WMI:
Win32_Process Class
            The Win32_Process WMI class represents a process on an operating system.
            class Win32_Process : CIM_Process
              string Caption;                           
              string CommandLine;
              string CreationClassName;
              datetime CreationDate;
              string CSCreationClassName;
              string CSName;
              string Description;
              string ExecutablePath;
              uint16 ExecutionState;
              string Handle;
              uint32 HandleCount;
              datetime InstallDate;
              uint64 KernelModeTime;
              uint32 MaximumWorkingSetSize;
              uint32 MinimumWorkingSetSize;
              string Name;
              string OSCreationClassName;
              string OSName;
              uint64 OtherOperationCount;
              uint64 OtherTransferCount;
              uint32 PageFaults;
              uint32 PageFileUsage;
              uint32 ParentProcessId;
              uint32 PeakPageFileUsage;
              uint64 PeakVirtualSize;
              uint32 PeakWorkingSetSize;
              uint32 Priority;
              uint64 PrivatePageCount;
              uint32 ProcessId;
              uint32 QuotaNonPagedPoolUsage;
              uint32 QuotaPagedPoolUsage;
              uint32 QuotaPeakNonPagedPoolUsage;
              uint32 QuotaPeakPagedPoolUsage;
              uint64 ReadOperationCount;
              uint64 ReadTransferCount;
              uint32 SessionId;
              string Status;
              datetime TerminationDate;
              uint32 ThreadCount;
              uint64 UserModeTime;
              uint64 VirtualSize;
              string WindowsVersion;
              uint64 WorkingSetSize;
              uint64 WriteOperationCount;
              uint64 WriteTransferCount;

            Caption         - Short description of an object—a one-line string.
            ExecutablePath  - Path to the executable file of the process. (Example: C:\WINDOWS\EXPLORER.EXE)
            ProcessId       - Global process identifier that is used to identify a process. 
                                The value is valid from the time a process is created until it is terminated.
 	public static ArrayList GetProcessList()
            ArrayList processList = new ArrayList();

            SelectQuery selectQuery = new SelectQuery("select * from Win32_Process");

            using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery))
                ManagementObjectCollection processes = searcher.Get();
                foreach(ManagementObject process in processes)
                    if (process.Properties["ExecutablePath"].Value != null)
                        string processCaption = process.Properties["Caption"].Value.ToString();
                        string processExePath = process.Properties["ExecutablePath"].Value.ToString();
                        //int processID = Convert.ToInt32(process.Properties["ProcessId"].Value.ToString());
                        string processID = process.Properties["ProcessId"].Value.ToString();
                        processList.Add(new ProcessData(processCaption, processExePath, processID));

            processList.Sort(new ProcessDataComparer());

            return processList;
where supporting classes are:
//ProcessData class
    class ProcessData
        public string Caption = "";
        public string ExePath = "";
        public string ProcessID = "0";

        public ProcessData(string processCaption, string processExePath, string processID)
            Caption = processCaption;
            ExePath = processExePath;
            ProcessID = processID;

    //for sorting:
    class ProcessDataComparer : System.Collections.IComparer
        public int Compare(Object processData1, Object processData2) 
            return String.Compare(((ProcessData)processData1).Caption, ((ProcessData)processData2).Caption);

NetworkCredential - How to Connect to "Secured" web service - Web Service requires authentication:

Open Dataset from Text File - How to Connect Dataset to a Text File:
Using .NET Dataset we can connect to Text File (with using schema.ini) and load data from text file into ListView or GridView:
	    	string textFilePath = @"c:\test_to_load.txt";

		DataSet dataTextFile = new DataSet("textfile");
		if ( ! LoadTextFile ( textFilePath, dataTextFile, out errorInfo) )
			MessageBox.Show("Failed to load text file:\n"  + errorInfo,
				"Load Text File");
			MessageBox.Show("File Loaded:\nTables:"  + dataTextFile.Tables.Count.ToString() 
				+ "\nRows:" + dataTextFile.Tables[0].Rows.Count.ToString() ,
				"Load Text File");

where LoadTextFile() method:
		private bool LoadTextFile( string textFilePath, DataSet dataToLoad, out string  errorInfo )
			errorInfo = String.Empty;

				string textFileFolder = ( new System.IO.FileInfo (textFilePath)).DirectoryName;
				string textConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
												"Data Source=" + textFileFolder + ";" +
												"Extended Properties=\"text;\";" ;
				//from using System.Data.OleDb:
				OleDbConnection textConnection = new OleDbConnection (textConnectionString);


				textFilePath = (new System.IO.FileInfo(textFilePath)).Name;
				string selectCommand = "select * from " + textFilePath;

				//open command:
				OleDbCommand textOpenCommand = new OleDbCommand(selectCommand);
				textOpenCommand.Connection = textConnection;

				OleDbDataAdapter textDataAdapter = new OleDbDataAdapter( textOpenCommand );

				int rows = 	textDataAdapter.Fill(dataToLoad);


				return true;
			catch (Exception ex_load_text_file)
				errorInfo = ex_load_text_file.Message;
				return false;

showModalDialog problem - javascript problem - open webform with client script but cant close it...
When you use showModalDialog() to open a "pop-up" dialog window, and then trying to use JavaScript method within the "pop-up" window, browser opens a new window with "javascript:" as an URL address...
Using <base target="_self" /> and <iframe> element helps.
For example, in your "parent" page:
	<body style="width:400px">
	 <script language=javascript>
            function open_appointment_list(client_id)
                var url = 'appointment_list_frame.aspx?clientid=' + client_id;
                var settings = 'dialogHeight:430px;dialogWidth:650px;status=no;'
                var result = window.showModalDialog(url,null,settings);
		while (result == 1 )
			result = window.showModalDialog(url,null,settings);
Then, in the "child" frame page (in my example it is called add_appointment_frame.aspx):
	<body style="width:400px">
		<iframe style="border:0px" 
So in "client" frame page, I only have one element - <iframe>, pointing to the actual "child" dialog window (in my example, appointment_list.aspx).

Article keywords: ApplicationLog_OnEntryWritten, OnEntryWritten, EnableRaisingEvents, EventLog.SourceExists(), EventLog.CreateEventSource(), Win32_ConnectionShare, Win32_Process, WMI, ManagementObjectSearcher, SelectQuery("Win32_ConnectionShare"), ManagementObject, Dependent("NumberOfFiles"), GetObject("WinNT://./LanManServer"), Windows.Resources, NetworkCredential, System.Net, Basic Authentication, Integrated Windows Authentication, System.Net.CredentialCache.DefaultNetworkCredentials, System.Collections.IComparer, IComparer, base, iframe, showModalDilog(), javasript,

Web being sponsor - Mid-Atlantic Processing. Well being sponsor - Clarity MediSpa. Hairless sponsor - Clarity MediSpa Laser Hair Removal.
Siccolo - SQL Server Management Tool For Mobile Devices is packed with built-in functionality and tools. Siccolo delivers a rich set of management tools for both DBAs and sys admins. SQL Server management has always been an area of DBA concern. The new Management Tool For Mobile Devices - Siccolo - has simple "Enterprise Manager" and the "Query Analyzer". Siccolo is a management tool for the MS SQL Server with administration capabilities and a database query tool. The administration features provide users the ability to browse database structures. An integrated query tool allows users to quickly create, edit and execute SQL queries and scripts. Siccolo also provides an export tool to allow users to easily save and email execution results. Siccolo helps database professionals save time and increase their productivity by utilizing a more efficient approach to database management - use their Windows Mobile empowered device while sipping margarita on the beach For increased security, Siccolo is configured to run under SSL with IIS authentication.
    Siccolo features are:
  • Run SQL Query window (with semi-automated Insert/Update/Delete/Select Statements) Open/Save SQL Scripts in multiple tabs Save/Email results
  • Explore SQL Server Browse databases and database objects (tables/views/stored procedures) Browse/Manage SQL Server jobs Browse/Manage windows services (start/stop) View event logs (Application, System)
  • Manage SQL Server - restart MS SQL Server service and SQL Agent

So, as we can see Web Services is quickly finding its way into major system integration development efforts. In back office and legacy systems alike, Web Servicess has become a main focus in providing mechanisms to make data move more freely between and across long-closed boundaries. An entire industry has joined forces and pushes forward in overcoming both technical hurdles such as security and market specific hurdles such as the need of standardized message formats. While these efforts continue, an entirely different market is rapidly maturing: the mobile devices, software and services market. Very interesting solution options arise in the cross section, where Web Services meets mobility. The Microsoft® Windows® .NET Compact Framework opens up the world of Web Services to Pocket PCs, and the wireless nature of Pocket PCs opens up the world of mobility to Web Services. This means that new fuel is added to the expansion of the XML-based Web Services provider market.