Rankspike

RSS
Sep
01

How to stop a hung service (starting or stopping) status

Sometimes us developer deals with server every now and then, although we are supported by Admin, there will be times that we have to do it on our own.

Here’s a simple way to stop or kill a hung service. When your service status is “stopping” or “starting” you can kill it using following simple command.

On command window : type

> sc queryex servicename

the reason is you want to get the PID to be able to kill it. Sometimes this doesn’t especially if the service name has spaces for instance “My App Service Prod” in that case use the following command to view them.

On command window: type

>tasklist /svc – this is a powershell command that would list or services with corresponding PID.

Once you’ve achieved the PID, here’s the command to kill it.

On command window: type

> taskkill /f /pid [servicepid]

This will force kill the hung service.

This article is brought to you by : First Brand Media LLC

 

 

Mar
30

How to check table size in SQL

Sometimes when you’re having an issue with database timing out or slowdown, it’s always worth to check and investigate the abnormal growth of the table size in your database. Here’s a simple script that may do just that.

USE YourDB
 
SELECT 
    t.NAME AS NameOfTable,
    s.Name AS NameOfSchema,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM 
    sys.TABLES t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    t.Name

 

Hope this helps someone who is currently investigating issues related to the Database.

 

This article is brought to you by: First Brand Media LLC

 March 30th, 2015  
 Gil Tabasa  
 SEO  
   
 0 Comment
Mar
02

How to create Rijndael key in ASP.NET c#

According to WIKI..

The Advanced Encryption Standard (AES) is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology (NIST) in 2001.[4]

AES is based on the Rijndael cipher[5] developed by two Belgian cryptographers, Joan Daemen andVincent Rijmen, who submitted a proposal to NIST during the AES selection process.[6] Rijndael is a family of ciphers with different key and block sizes.

For AES, NIST selected three members of the Rijndael family, each with a block size of 128 bits, but three different key lengths: 128, 192 and 256 bits.

AES has been adopted by the U.S. government and is now used worldwide. It supersedes the Data Encryption Standard (DES),[7] which was published in 1977. The algorithm described by AES is asymmetric-key algorithm, meaning the same key is used for both encrypting and decrypting the data.

In the United States, AES was announced by the NIST as U.S. FIPS PUB 197 (FIPS 197) on November 26, 2001.[4] This announcement followed a five-year standardization process in which fifteen competing designs were presented and evaluated, before the Rijndael cipher was selected as the most suitable (see Advanced Encryption Standard process for more details).

And here’s how to create one on C# can be used as plug and play.

using System.IO;
using System.Security.Cryptography;
 
private static readonly byte[] SALT = new byte[] { 0x26, 0xdc, 0xff, 0x00, 0xad, 0xed, 0x7a, 0xee, 0xc5, 0xfe, 0x07, 0xaf, 0x4d, 0x08, 0x22, 0x3c };
 
public static byte[] EncryptText(byte[] plain, string password)
{
    MemoryStream memoryStream;
    CryptoStream cryptoStream;
    Rijndael rijndael = Rijndael.Create();
    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, SALT);
    rijndael.Key = pdb.GetBytes(32);
    rijndael.IV = pdb.GetBytes(16);
    memoryStream = new MemoryStream();
    cryptoStream = new CryptoStream(memoryStream, rijndael.CreateEncryptor(), CryptoStreamMode.Write);
    cryptoStream.Write(plain, 0, plain.Length);
    cryptoStream.Close();
    return memoryStream.ToArray();
}
 
public static byte[] DecryptText(byte[] cipher, string password)
{
    MemoryStream memoryStream;
    CryptoStream cryptoStream;
    Rijndael rijndael = Rijndael.Create();
    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, SALT);
    rijndael.Key = pdb.GetBytes(32);
    rijndael.IV = pdb.GetBytes(16);
    memoryStream = new MemoryStream();
    cryptoStream = new CryptoStream(memoryStream, rijndael.CreateDecryptor(), CryptoStreamMode.Write);
    cryptoStream.Write(cipher, 0, cipher.Length);
    cryptoStream.Close();
    return memoryStream.ToArray();
}

As you may have noticed that the cipher passed here is in byte and so is the encrypt, this can be the generated byte array from your own key generator.

 March 2nd, 2015  
 Gil Tabasa  
 ASP.NET, ASP.NET 4.5, How to-, Programming, Visual Studio 2012  
   
 0 Comment