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.