Saturday, May 30, 2009

How to UnRegister .NET Windows Service ?


Use the below script to unregister a windows Service.

Step 1: Create a batch file (eg., UnRegister.bat) and put it in the same foler where your windows service executable file resides).

Step 2: Copy the below script and paste it in above "UnRegister.bat" file.

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo UnInstalling WindowsService...
echo ---------------------------------------------------
net stop WINDOWS_SERVICE_NAME
InstallUtil /u WINDOWS_SERVICE.EXE
echo ---------------------------------------------------
pause
echo Done.

Step 3: Replace your windows Service executable file with "WINDOWS_SERVICE_NAME" and "WINDOWS_SERVICE.EXE" string.

Step 4: Save -> Exit from the file. Now the batch file is reay to uninstall the windows service. Just double click the "UnRegister.bat" file.

How to Register .NET Windows Service ?

Registering a Windows Service is always a challenge .

I personally prefer to write / use a script. Below is a script which will install a Windows Service and start it once its installed properly. By default it will set the Mode "Automatic When windows OS starts".


Step 1: Create a batch file (eg., Register.bat) and put it in the same foler where your windows service executable file resides).

Step 2: Copy the below script and paste it in above "Register.bat" file.

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing WindowsService...
echo ---------------------------------------------------
InstallUtil /i WINDOWS_SERVICE_NAME
net start WINDOWS_SERVICE.EXE
echo ---------------------------------------------------
pause
echo Done.


Step 3: Replace your windows Service executable file with "WINDOWS_SERVICE_NAME" and "WINDOWS_SERVICE.EXE" string.

Step 4: Save -> Exit from the file.

Now the batch file is reay to install the windows service. Just double click the "Register.bat" file.

Isn't it very easy !!!!

Monday, May 18, 2009

RollUp 4 release for MS CRM 4.0


Microsoft has release rollup 4 for CRM 4. KB952858 can be downloaded here.

This is a tested, cumulative set of updates for Microsoft Dynamics CRM 4.0. It includes performance enhancements that are packaged together for easy deployment.

Please note that if you have customized Microsoft Dynamics CRM 4.0 Help files, back up your customized files before you install this update !!!

Sunday, May 17, 2009

Invalid Action - The selected action was not valid.


I download new MS CRM VPC (April 2009), When I browse the MS CRM Default organization (contoso)I discovered that we were receiving a very descriptive "Invalid Action: The selected action was not valid" error message.

Then, I checked the system's Application Event Log. LOL, I found the following error message:
Source: Current active key (KeyType : CrmWRPCTokenKey) is expired. This can indicate that a key is not being regenerated properly. Current Active Key : CrmKey(Id:e1a5b215-d01e-de11-9d16-0003ffd0167c, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:04/01/2009 15:16:36, ExpiresOn:05/04/2009 15:16:36, CreatedOn:04/01/2009 15:16:36, CreatedBy:NT AUTHORITY\NETWORK SERVICE. Key Setting :


Fortunately, this problem was easily solved by running services.msc and starting the Microsoft CRM Asynchronous Processing Service.

Always look into Event Log messages for quick error resolutions (MS, Pls give more info, dont just put the kb link :( )

Saturday, May 16, 2009

Read a Text File Line by Line using C#


Here is the sample code:

string file_name = @"c:\list.txt";
System.IO.StreamReader ObjReader = new System.IO.StreamReader(file_name);
do
{
MessageBox.Show(ObjReader.ReadLine());
} while (ObjReader.Peek() != -1);


Happy Programming !!!!

Recover Corrupt SQL Server Database


This is quiet common while working on VPC (MS CRM VPC) that when the VPC gets close abnormally.

When you restart the VPC and try to open MS CRM Web you will see some SQL SERVER (Database Corrupt) related error. When you open SQL Server Enterprises studio and we will observe that the database is in SUSPEND mode. And this is due to the VPC gets close abnormally.

But still you can recover the DATABASE. Use the below set of SQL Statement .

EXEC sp_resetstatus 'MicrosoftCRM_MSCRM';
ALTER DATABASE MicrosoftCRM_MSCRM SET EMERGENCY

DBCC checkdb('MicrosoftCRM_MSCRM')
ALTER DATABASE MicrosoftCRM_MSCRM SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CheckDB ('MicrosoftCRM_MSCRM', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE MicrosoftCRM_MSCRM SET MULTI_USER

MicrosoftCRM_MSCRM is database name (for example purpose). When you use this script to recover the database replace MicrosoftCRM_MSCRM with your database name.

Enjoy. Happy recovering corrupt SQL Server Database.

IsNullOrEmptyOrNoValue() - Extension of IsNullOrEmpty()

public static bool IsNullOrEmptyOrNoValue(string strValue)
{

return (string.IsNullOrEmpty(strValue) ? true : (string.IsNullOrEmpty(strValue.Trim()) ? true : false));

}

Parameters
value
Type: System.String
A String reference.

Return Value
Type: SystemBoolean

true if the value parameter is a null reference (Nothing in Visual Basic) or an empty string (""); or the trim value is empty otherwise, false.

Remarks
IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is a null reference (Nothing in Visual Basic) or its value is Empty or the trim value is empty.


IIS Log File Location


Here is the solution.

Location of IIS log files:

Windows Xp:
C:\WINDOWS\system32\Logfiles\W3SVC1

Windows NT/2000:
C:\WINNT\system32\Logfiles\W3SVC1


Visual Studio 6 Error - Cannot find file ACMBOOT.EXE (or one of its components).


I was happen to install Visual Studio 6.0 for one of my project. As soon as Run the Professional Edition i got the below error -

Cannot find file ACMBOOT.EXE (or one of its components). Check to ensure the path and filename are correct and that all required libraries are available.

If you are getting the same error as above please follow the below steps to resolve the issue:

1. make a copy of your installation cd in your hard drive
2. make a copy of the setup/VS98ENT.STF and name it acmsetup.STF
3. copy entire content of setup/ to previous folder (the one that has acmboot.exe file)
4. run acmsetup.exe instead of setup (the one that's on the same path as acmboot.exe)
5. voala, that's it, your visual studio 6.0 will be installed.

Isn't it easy !!! Happy Development.