Sunday, 18 March 2018

How to parse json data in table row using MS SQL OPENJSON

Description : In this post how to parse json data in MS SQL using OPENJSON first we need json here declare one json variable and set static json in this variable. write one select querye with OPENJSON for convert json to SQL Table

DECLARE @json NVARCHAR(MAX)

SET @json = 
N'[ 
       { "name": "Test 1", "surname": "Testing" },
       { "name": "Test 2", "surname": "Testing Again" }
 ]' 

SELECT * FROM OPENJSON(@json) 
WITH (
    FirstName nvarchar(50) '$.name'
    , LastName nvarchar(50) '$.surname'
)

Below screen shot display how to write query of OPENJSON



Below screen shot display how result look like

How to check file exists in FTP server in C#

Description : In this post when you try to delete file from FTp but get error 550, File Unavailable to solve this first check file is exists or not in FTP.
here create one method for check file in FTP

private bool FileCheckInFTP(string fileName)   
{   
    var request = (FtpWebRequest)WebRequest.Create("ftp://www.server.com/" + fileName);   
    request.Credentials = new NetworkCredential("username", "password");   
    request.Method = WebRequestMethods.Ftp.GetFileSize;   
       
    try   
    {   
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();   
        return true;   
    }   
    catch (WebException ex)   
    {   
        FtpWebResponse response = (FtpWebResponse)ex.Response;   
        if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)   
            return false;   
    }   
    return false;   
}

- if the response get from FTP like "ActionNotTakenFileUnavailable" it means file is unavailble.