Thursday, September 22, 2011

Uninstalling from Command-line in Windows
The Windows Management Instrumentation Console is the utility provided by Microsoft to remove installed programs/applications from command-line. There are situations where the default uninstall utility chipped with your windows operating system fails to remove some applications that you have either gone berserk or you have tagged "Unwanted". For such situtations, the WMIC could come in handy for this "harvest".

From your command line, perform the following:

1. Type "wmic" without the double quotes;
2. In the wmic prompt, type "product get name " also without the double quotes. This enlists all the installed applications on your system. Locate the application you want to "harvest" and proceed with 3
3. Type "product where name ="" call uninstall". 
For example: product where name="Test Application" call uninstall

Accept the prompt question by supplying a "y". Then you are done.

For applications that are still uninstalled after the above processes, consider using an appropriate 3rd party uninstall utility.

Tuesday, April 05, 2011

In ability to create Database Diagram



If after you attach the MDF of an SQL Server Database, you are unable to create Database Diagrams and you get the following error each time you try:

"TITLE: Microsoft SQL Server Management Studio ------------------------------ Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects."


The SQL Server is intelligent and also correct that your newly attached Database does not have a valid owner yet. Therefore, you new to locate a valid user on your SQL Server and assign the database to this user.

Running the following SQL command in your Query Window assigns the database to the user and you should be able to create your diagrams henceforth:

"ALTER AUTHORIZATION ON DATABASE::databaseName TO domain\user"

Saturday, May 22, 2010

Error starting the MSSQLSERVER service:

In midst of developing a crash app for a client, I have fired up ER models in SQL Server. For a demonstration that was due in 2 days, I had to work longer than usual. Anyway, working longer really might not mean work harder. I had a couple of frameworks that could deliver a seemingly robust application in split seconds.

Just 24 hours after commencement, I was also done with the entire product. It was a database-driven web application. I conducted an end-to-end testing and everything seemed perfect. I have eventual saved a day I thought!

There is this gal that I mentor! Just mentoring and nothing else before you begin to whistle. She just crashed her laptop. Adn being the Big brother that I am, I allowed her access on mine. I forgot the rule "Never leave a kid alone with a gadget" and that really burnt me!

By the time I returned, she had left and i just didn't have a stint of what could have happened on my lappy while i was away.

However, being a quite observant individual, I noticed that the naming of all my foldes were "BLUE" and that tells me that my harddrive had been compressed! I did not bother. Maybe she was trying toi save herself some spaces on my lappy i thought.

I got a call from the client and I had to make a litle ammendment to the codes. I launched VS2005 but my SQL Server refused to wink. I could not connect to the database. I knw there was problem. Demo was just 30minutes away by then.

They sudden pressure that held me made me forget everything. But ihad to put this database back on. MOreso, I had collected an upfront payment for the demo app.

Everytime I try to start the service I get this error:

"SQL Server 2005 Error code 3417: Windows cannot start the SQL Server (MSSQLSERVER) on Local Computer. For more Information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 3417."

in a nutshell, I resolved in just bout 5minutes to demo time. All I did was to uncompress the
"C:\Program Files\Microsoft SQL Server" directory and all of its children folders.

The service stated successfully afterward. The sweat I saved coding were eventually used up troubleshooting

Wednesday, July 09, 2008

Dependency Injection: Simple Complexity (Part I)


Uhm... I don't know why some geniuses amongst us like to make life simply complex for some of us. It is has been really hectic figuring out the core meanings and interpretation of hypothesis in this domain we found ourselves - Software Solution Development Domain.

It is almost becoming a strength-test terrain, where only the strong survives. Without the extra gut to ask the extra HOW & WHY, in fact, one might be frustrated in no time at all to join Nollywood and do the do like they do. Apology to my powerful artists.

I have been hearing about some very bogus terms for some times now. The "bigness" of these words scared me and i dared not examine what their concoction really meant. I was trapped in this locker until I came across someone who resounded them - "Dependency Injection / Inversion Of Control". What tha hell? I thought.

Imagine the freedom of a baby wandering in a lion's den without the awareness of the danger looming ahead. That was the feeling I got from this newbie. He was just reading everything and implementing all. He thought I would be a good lead. he rushed to be when he was flogged. Exactly thesame way that baby would run for help sighting the lion in its den.

But really, this lion could have been a screensaver, to the beautiful world behind it. Just a simply complex way to infiltrate spoilers. And sometimes it could be real - DANGER. In whatever way, how do you find out?

Get closer and probably, Touch!!!

I rushed back and in very simple terms these are my findings:

1: After runnig to dictionaries, Dependency mean "rely on", "need", "made up of". Grammarians, please help me out.

So in a programmic expression, dependency means that a class needs an object of another class in its creation. SIMPLY COMPLEX?

Example:
First discreet class Heart is defined as:


public class Heart
{
int beat = 0;

public int Beat
{
get{return beat;}
set{beat = value;}
}
}

Now, Learn dependency. lol:

public class Man
{
Heart heart = null;

public Man()
{
this.heart = new Heart();
}
}

You know what that means. No Heart, no Man. So you could say that Man depends on Heart. SIMPLY SIMPLE.


Moving further, Injection. What does it mean? By the dictionaries also, Injection could mean "Introduce", "put into", "put in a place" and the list could grow.

Programically speaking, it means that you can, using the above example, give a potentially Heart-broken Man a Heart. Lover boys, come along.

Example:

public class Man
{
.
.
.
public Man(Heart heart)
{
//use heart up here
}
}

We have succeeded in injecting a heart into a Man without one. lol.

This is not the limits of what you could do with DI. When you exhaust this, we'll move on up like Access bank.

Now tell me what you don't know about DI. Martin Fowler has only tried to bamboozle our minds with some big grammars. It is a only a way to advertise a 5cents product using a 5million dollar TV station platform. But think about 5million of 5cent. That is where the complexity sets in

Think about it

Friday, September 07, 2007

Before ORMs and the LINQ:

"If only I was Bill Gates..."

I was a massive database application developer. In those times I developed Apps that interacted heavily with the back-ends (all sort of back-ends). From my first love MS SQL Server to PostgreSQL, from Oracle to HSQL and the list could grow. Initially I was passionate about doing these heavy transactional developments. But at a later time, I got almost frustrated as most of the things I do in these different apps look too much alike. Copy and paste could be cool sometimes, but not without some slight tweaks. (Even this could be worse of sometimes).

Big guns in software development might snub this article and call me a “rabbit” (Chess slogan for a novice), but truth is we all started from somewhere. This was in my past. I was a novice though, specifically to some tools, but not basically to DB-programming.

I was furious and decided to find a way to overcome this nightmare of re-inventing the wheel. We have heard about code reusability but growing up alone in the realm I found myself was a bit tasking. I had to be finding out on my own stuff I could do to make life easy for me and probably put me on the leverage with the so-called “BABAs” in the field.

Code reusability does not necessarily mean using a chunk of codes in different projects. In fact, as a matter of fact, we have found more code reusability scenarios in the different parts of the same project more often than we see in different projects. So I let my mind got blown with my fantasy and I just exploded. I taught this technique amidst my peers. (If they had understood it then, maybe I would have made a theory that would have been generally accepted).

My Technique

I built a database schema. Looked at it critically and resolved not to ever write the same lines of code twice for any application that will sit atop of it. I have heard about application tiers. I just wanted to explore and probably, explode. I was at this time in my third year in the University – Olabisi Onabanjo University. For those that know the standard back in my school was, you will understand what I mean.

I read extensively (at least to the best of materials at my disposal) and settled to use the 3-tier methodology. I felt funny about this at first considering the fact that I only had a PC (top of the range though: a P4 1.6GHz 256DDRAM). But 3-tier application could work on a single PC.

I just continued……

First, I built a .dll I called the “Data Layer”. The responsibilities of this component are:

  • To ensure a single point of entry to my DB;
  • To ensure a single point for DB query on my DB;
  • To better control DB connections.
  • To keep a persistent Dataset object to act as a virtual DB;
  • To fulfil my promise: “to ever write the same lines of code twice for any application….”

Next was….

I built a C# classes. Each of these classes resembles a database table I have in my back-end. Confused?

Ok it is like this. Assuming you have a database table that has 3 columns namely: SSN, Surname, DateOfBirth, then you’ll create a class that totally resembles that table. Your class would so have 3 fields too namely: SSN, Surname and DateOfBirth. The datatype of corresponding columns and fields must match too. I varchar mapped to string, Integer to int. And so on.

Normally there few operations you can ever perform on a db table. They are: Insertion of new records, deletions of records, search of records and Update of records. Any more? Tell me if there are more…

So I gave each class the responsibility of performing these major operations on the table they simulate. These responsibilities are basically the methods or operations of the classes.

Eureka! Eureka!! Eureka!!! I have found it

Eventually when I built the User interface, my code-behind was very concise and neat. Imagine (for example, to add a new student to the DB, you write something like “

student.Add()”.

To search for a particular student with matric number 00001, you’d wirte something like:

Student st = Student.find(0001);

And you can be sure that the values the “st” object variable is holding is everything about the student whose matriculation number is 0001

That was all.

I was elated. I just ran to compile a book (which never gets published) and was thinking about the name to give this approach I thought was new and totally developed by me. Good I thought and felt like a master. I gathered a small team in school and trying to relay this methodology to them. They did not understand. I wanted to perfect the “new” methodology so I hooked up on the net to get some more materials on Database programming. This was the point I felt “good-bitter” about my discovery. I found “Hibernate”and “NHibernate”, both ORMs and they were all I thought I discovered.

I just “smiled-crying”. Hibernate exists but I found it before I saw it. I felt good. “I am coming up” I said to myself. It was just some good stuff…

However, with the latest Beta version of the MS Visual Studio, LINQ made the spoils I have always dreamt about. Language Integrated Query: The perfect way to do DB programming easier and faster.

Thursday, September 06, 2007

TIMING YOUR EVENTS: The .NET Party

It is a popular saying in Yoruba language (permit me to use it) that “enikan ki I bu sango l’erun” (meaning no one invokes the god of thunder in the dry season). Whatever this means, timing is crucial to the menace (or benefits if any) of the invocation of the god of Thunder. Even when all recipes are available, it is important it be raining season for the effects to be significant. So are the timer controls in .NET. Did I hear you say “timer controls”?

When I started out being a .Net developer, sequel to my background as a VB developer, I deemed the timer control as “unified”. By this unification, I suppose that in whatever scenario where one needs to invoke some sequence of operations at intervals, the “visual” timer control would be sufficient. Damn!!! I was wrong.

There isn’t anything like “visual” timer control. I am only trying to insinuate an instance of the “System.Windows.Form.Timer” class; which is the only visible timer control in .Net (at least in the toolbox). By this visibility, a lot of naïve (did I use that word?) developers like me thought that was all .Net has got to offer about timing your events until the last time it failed. This time, I was building a Windows Service.

The Motivation:

I was required by a superior to develop an Application such that:

· Requires little or NO user interactions;

· Runs in the background of the OS;

· Performs a set of routines at specified intervals; basically every morning, every Monday and every start of a new month;

My Analysis:

With the set of requirements above, I needed not to be told any further that I needed to build a Windows Service App that keeps track of time change. In order to track time changes, I know a timer control is a definite option. The System.Windows.Form.Timer Class provides the nearest timer to use, so I delved into development. Though, I was not cautious of the fact that I was invoking the wrong Timer instance.

The following were what I did:

· Dragged and dropped the System.Window.Forms.Timer Timer control on the Windows service interface;

· Set the enabled property of the timer control to True;

· Set interval to 5000 (ms);

· Wrote loads of logics in the Tick method of the Timer control;

· Built it (no error was returned);

· Deployed the application but the logics in the Tick method of the Timer control never got invoked;

· Then my frustration, motivation, research, discovery and finally, this article.

My Flaw:

Just as it is healthy to read the prescription inscribed at the back of tablets pack before usage, it is also highly placed as important to read the documentation of every control provided in any development environment before applying them to use.

The System.Windows.Forms.Timer Timer control implements a timer that raises an event at user-defined interval. This timer is optimized for use in Windows Forms applications and MUST be used in a Window. This is the vendor’s (Microsoft) recommendation, which I skipped and eventually ran into a ditch. Good for me though. I read the prescription after taking the dosage; this time, overly.

My Research:

After examining why my Tick event wasn’t getting invoked, I discovered that I wasn’t meant to use a control that was meant strictly for a Windows Form in the Development of a Windows Service. My conviction of using a Timer control persisted given the requirements like my superior.

I found out that .Net provides three types of the Timer Control. Each optimized for there various environments.

· System.Windows.Forms.Timer Class instance

· System.Timers.Timer class instance

· System.Threading.Timer class instance.

System.Windows.Forms.Timer Class instance

This implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.

This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread.

When using this timer, use the Tick event to perform a polling operation or to display a splash screen for a specified amount of time. Whenever the Enabled property is set to true and the Interval property is greater than zero, the Tick event is raised at intervals based on the Interval property setting.

This class provides methods to set the interval, and to start and stop the timer

Example:

[C#]

public class Class1

{

static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();

static int alarmCounter = 1;

static bool exitFlag = false;

// This is the method to run when the timer is raised.

private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs)

{

myTimer.Stop();

// Displays a message box asking whether to continue running the timer.

if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter, MessageBoxButtons.YesNo) == DialogResult.Yes)

{

// Restarts the timer and increments the counter.

alarmCounter +=1;

myTimer.Enabled = true;

}

else

{

// Stops the timer.

exitFlag = true;

}

}

public static int Main()

{

/* Adds the event and the event handler for the method that will process the timer event to the timer. */

myTimer.Tick += new EventHandler(TimerEventProcessor);

// Sets the timer interval to 5 seconds.

myTimer.Interval = 5000;

myTimer.Start();

// Runs the timer, and raises the event.

while(exitFlag == false)

{

// Processes all the events in the queue.

Application.DoEvents();

}

return 0;

}

}

System.Timers.Timer class instance

This Timer component is a server-based timer, which allows you to specify a recurring interval at which the Elapsed event is raised in your application. You can then handle this event to provide regular processing. For example, suppose you have a critical server that must be kept running 24 hours a day, 7 days a week. You could create a service that uses a Timer to periodically check the server and ensure that the system is up and running. If the system is not responding, the service could attempt to restart the server or notify an administrator.

The server-based Timer is designed for use with worker threads in a multithreaded environment. Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy than Windows timers in raising the event on time

Note The event-handling method might be called even after the Stop method is called. The event-handling method might run on one thread at the same time that a call to the Stop method runs on another thread. This might result in the Elapsed event being raised even after the Stop method is called. To prevent this, use the SignalTime property to compare the time the event was raised to the time the Stop method was called. If the event was raised after the Stop method was called, do not process the event.

The Timer component raises the Elapsed event, based on the value of the Interval property. You can handle this event to perform the processing you need. For example, suppose that you have an online sales application that continuously posts sales orders to a database. The service that compiles the instructions for shipping operates on a batch of orders rather than processing each order individually. You could use a Timer to start the batch processing every 30 minutes.

Note When AutoReset is set to false, the Timer raises the Elapsed event only once, after the first Interval has elapsed. To keep raising the Elapsed event on the Interval, set AutoReset to true.

The Timer is not visible at run time.

Example

[C#]

public class Timer1

{

public static void Main()

{

System.Timers.Timer aTimer = new System.Timers.Timer();

aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);

// Set the Interval to 5 seconds.

aTimer.Interval=5000;

aTimer.Enabled=true;

Console.WriteLine("Press \'q\' to quit the sample."); while(Console.Read()!='q');

}

// Specify what you want to happen when the Elapsed event is raised.

private static void OnTimedEvent(object source, ElapsedEventArgs e)

{

Console.WriteLine("Hello World!");

}

}

System.Threading.Timer class instance

Use a TimerCallback delegate to specify the method you want the Timer to execute. The timer delegate is specified when the timer is constructed, and cannot be changed. The method does not execute on the thread that created the timer; it executes on a ThreadPool thread supplied by the system.

When you create a timer, you can specify an amount of time to wait before the first execution of the method (due time), and an amount of time to wait between subsequent executions (period). You can change these values, or disable the timer, using the Change method.

NoteNote:

As long as you are using a Timer, you must keep a reference to it. As with any managed object, a Timer is subject to garbage collection when there are no references to it. The fact that a Timer is still active does not prevent it from being collected.

When a timer is no longer needed, use the Dispose method to free the resources held by the timer. To receive a signal when the timer is disposed, use the Dispose(WaitHandle) method overload that takes a WaitHandle. The WaitHandle is signaled when the timer has been disposed.

The callback method executed by the timer should be reentrant, because it is called on ThreadPool threads. The callback can be executed simultaneously on two thread pool threads if the timer interval is less than the time required to execute the callback, or if all thread pool threads are in use and the callback is queued multiple times.

NoteNote:

System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by thread pool threads. It is not recommended for use with Windows Forms, because its callbacks do not occur on the user interface thread. System.Windows.Forms.Timer is a better choice for use with Windows Forms. For server-based timer functionality, you might consider using System.Timers.Timer, which raises events and has additional features.


C#

using System;

using System.Threading;

class TimerExample

{

static void Main()

{

AutoResetEvent autoEvent = new AutoResetEvent(false);

StatusChecker statusChecker = new StatusChecker(10);

// Create the delegate that invokes methods for the timer.

TimerCallback timerDelegate =

new TimerCallback(statusChecker.CheckStatus);

// Create a timer that signals the delegate to invoke

// CheckStatus after one second, and every 1/4 second

// thereafter.

Console.WriteLine("{0} Creating timer.\n",

DateTime.Now.ToString("h:mm:ss.fff"));

Timer stateTimer =

new Timer(timerDelegate, autoEvent, 1000, 250);

// When autoEvent signals, change the period to every

// 1/2 second.

autoEvent.WaitOne(5000, false);

stateTimer.Change(0, 500);

Console.WriteLine("\nChanging period.\n");

// When autoEvent signals the second time, dispose of

// the timer.

autoEvent.WaitOne(5000, false);

stateTimer.Dispose();

Console.WriteLine("\nDestroying timer.");

}

}

class StatusChecker

{

int invokeCount, maxCount;

public StatusChecker(int count)

{

invokeCount = 0;

maxCount = count;

}

// This method is called by the timer delegate.

public void CheckStatus(Object stateInfo)

{

AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;

Console.WriteLine("{0} Checking status {1,2}.",

DateTime.Now.ToString("h:mm:ss.fff"),

(++invokeCount).ToString());

if(invokeCount == maxCount)

{

// Reset the counter and signal Main.

invokeCount = 0;

autoEvent.Set();

}

}

}


Friday, August 11, 2006

Introducing "IS IT IT?
"My people perish for lack of Knowledge"

Tautology? Not really. I had a thought and before I could whisper a word, I asked myself if it is it. This paragraph is not to give you the idea behind this title. My notion is for you to fix it by yourself.

The most amazing thing about this header is that it asks a question and at the same time, answers it. Ask me how. Replace each of the "IT" with "Information Technology", one at a time, then you will come up either "IS INFORMATION TECHNOLOGY IT?", or "IS IT INFORMATION TECHNOLOGY?"

Anyway, I'll be publishing my IT-related articles and thoughts here. I hope you will enjoy every bit of it.

Now I have to return to the desk. Enjoy!!!