Friday, November 30, 2012

c# - Convert a string to lowercase,uppercase without using builtin functions

LOWERCASE 

try
{
    string s = "This Is A Sentence!!!";
    char[] ca = s.ToCharArray();
    foreach (char c in ca)
    {
       if ((int)c < 91 && (int)c > 64)
          Console.Write(((char)((int)c + 32)));
       else
          Console.Write(c);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}















UPPERCASE

try
{
    string s = "This Is A Sentence!!!";
    char[] ca = s.ToCharArray();
    foreach (char c in ca)
    {
        if ((int)c < 123 && (int)c > 96)
           Console.Write(((char)((int)c - 32)));
        else
           Console.Write(c);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
 
     

Tuesday, November 27, 2012

SSPI handshake failed with error code - SQL Server 2008

If you have worked on SQL Server migration then its likely that you have come across this error message.I recently migrated a server from SQL Server 2005 to SQL Server 2008.Everything seemed to go well except that I started seeing this error message in the SQL Server Log,Event viewer.
























After searching the internet for the causes and trying the fixes, the issue wasn't fixed.Some of the checks I did were to recreate the SPN's,Set the DisableLoopbackCheck registry entry to 1 (Note this fix worked for another server) ,verify NTLM or KERBEROS authentication and so on.

So I decided to contact our DBA and it took 5 minutes to figure out the issue.
First thing was to figure out the offending application.So he ran a trace on Audit Login Events in SQL Profiler

















The account to connect to the report server was not configured correctly and that was causing the error.Once the Report Server was configured the error disappeared.

Open Report Server Configuration Manager



















Configure Report Server Service Account and provide the correct credentials




 The trace now correctly shows that the account login was successful.
Restart the Report Server and now SQL Server Log does not show the SSPI handshake failed error 


SQL Profiler Rocks !!! Hope this helps.

Wednesday, November 21, 2012

Bulk load: An unexpected end of file encountered in the data file - SQL Server

I have a SQL Server job that loads certain columns from a tab delimited text file into a SQL Server database table.The job was working fine until recently it started throwing the below error.






This error occurs when there are null values in the one the columns that you are trying load to the table.In order to fix the issue, the bulk insert command must be run with the 'KEEPNULLS' option.

For more information on the BULK INSERT with KEEPNULLS see the following link. http://msdn.microsoft.com/en-us/library/ms187887.aspx




Friday, November 16, 2012

Linked server was unable to start a distributed transaction - SQL Server

Recently I migrated a server  to Windows Server 2008 and the database from SQL Server 2003 to SQL Server 2008.After the migration one of the web applications started throwing this error.


























To fix this I had to enable the distributed transaction coordinator on the server that application was trying to access.


After I did this the error message changed to MSDTC is unavailable on the server .



To fix this I had to configure the MSDTC on the server that application was trying to access.The steps are listed in the following link.

Screenshots of the above steps is below.





Monday, November 12, 2012

Copy files between servers - Robocopy - Multithreaded option

Previously I have used XCOPY for copying huge files between two windows servers until I came across Robocopy's multithread option

Simplest form of robocopy with this option is below

robocopy source_folder destination_folder f* /MT /S /Z

where f* is all files starting with the letter f in the source_folder and /MT is the mulithreaded option.
Note that /MT automatically uses the total number of processors on the server you run the command.



Wednesday, November 7, 2012

c# - A to Z & a to z

Software Intern Interview question.Print A-Z using a loop

for (int iIndex = 65; iIndex <= 90; iIndex++)
    Console.WriteLine(((char)iIndex).ToString());



for (int iIndex = 97; iIndex <= 122; iIndex++)
     Console.WriteLine(((char)iIndex).ToString());



Friday, November 2, 2012

Copy files between servers - Windows Server

Previously I have always used the windows explorer GUI on the servers to copy files between two server network shares.I started getting errors "Insufficient System Resources to complete the requested service" once I started to copy huge files(20 GB) across the network.
This happens when the paged pool memory is insufficient.You can request IT to tweak the settings to get around the problem.

Instead of the GUI copy/paste option I now use XCOPY command to transfer files from one server to another.
More about xcopy here http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true

Simplest form of the command is  xcopy source destination

Log on the server and bring up the cmd prompt














In the command prompt type the command  

xcopy sourceserver_folderpath destinationserver_folderpath