Friday 15 July 2016

SonarQube4.0 with MS-SQL

Step by Step approach


Introduction to SonarQube

SonarQube is an open platform to manage code quality.

We are concentrating on Version 4.0, therefore
Download the SonarQube 4.0 and Sonar runner under related tools from the mentioned below URL
Unzip after download complete.
It requires JDK >6 to be installed.

Here, we have used SonarQube 4.0, Sonar-Runner 2.3 and JDK 7.

Steps to start scanning

           Open environment variable                                                                                    




         Create environment variables





  •     CLASSPATH                                                                                                              






  •  JAVA_HOME
  • SONAR_RUNNER_HOME
                                           


    1.       Update environment variable

    •         Path

    a

    MS-SQL requisites 

    Create empty database with name Sonar
    Create new login for SONAR to use the Database

    Create UserMapping  for Sonar database as db_owner


    Grant status

    After creation of Login, Verify the jdbc driver in SonarQube 4.0 unzip in the below mentioned path




    1.       Open sonarqube-4.0 > conf folder and open sonar (properties file)

    By default , sonar uses H2 database

    Note:- # in conf file means comment. Remove # to change (uncomment) the configuration.

    Open conf file ,  change username and password to sonar
    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar

    Go to MS-SQL section and change the connection URL and driverClassName

    #----- Microsoft SQLServer
    # The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net
    sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/Sonar;instance=SQLEXPRESS;SelectMethod=Cursor
    sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver
    sonar.jdbc.validationQuery: select 1

    Open sonar-runner x.x > conf > sonar-runner (properties file)
    Change the 
    #----- Microsoft SQLServer 
    sonar.jdbc.url= jdbc:jtds:sqlserver://localhost/Sonar;instance=SQLEXPRESS;SelectMethod=Cursor
    sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver

    #----- Global database settings
    sonar.jdbc.username= sonar
    sonar.jdbc.password= sonar

    After, database settings 
    Open command prompt (cmd) , move to the directory of sonar and execute startsonar.bat file




    After successful start you’ll get below shown screen

    Open browser and type URL http://localhost:9000/ 



    This shows the sonar is installed and running successfully. Next, download the file from below mentioned URL
    https://raw.githubusercontent.com/SonarSource/sonar-examples/master/projects/languages/java/sonar-runner/java-sonar-runner-simple/sonar-project.properties 

    But, during saving this doc. save it as .properties not as, txt 

    Go to, browser and login with default user credentials usn and pwd as admin. 
    Click settings
    Click update center
    Select available plugin and search for C# and download it.
    Copy the file and paste it to the folder \sonarqube-4.0\extensions\plugins.
    Logout and again Login from browser.
    The new plugin will present in the installed plugins.

    Copy the sonar-project.properties file and paste into the solution folder which requires to test code quality.
    Open the file. It requires some changes
    By default, the properties file will be having 



    Since we are using C# language set 
    sonar. Language = cs

    Open Command prompt. Change directory to the project location i.e., where the sonar-project.properties is located.
    Type sonar-runner.bat

    It starts processing of each and every code of line based on the rules insisted in database dbo.rules table.

    After successful execution , prompts as below shown image



    The step by step approach for using Sonar Qube 4.0 for .Net application with MS-SQL was documented for the current project quality maintenance.

    Please, guide me if something you feel is not right in the Post.

    Wednesday 1 July 2015

    GlobalConfiguration.Configuration.DependencyResolver not found WebAPI

    In my recent project , I found an interesting issue thought of posting it in my blog. 
    May be , this post will help other guys who are searching after the same issue.

    GlobalConfiguration.Configuration.DependencyResolver not found

    My project required dependency injection with Ninject. During registration of all the repositories to the kernel in Ninject configuration this issue came up.

    I searched the reason and did'nt found the reason . Later after searching for one hour, I came to know the reason that the project was basically started as MVC project and required with WebAPI also.

    Then the answer is simple , GlobalConfiguration is from the NameSpace  System.Web.Http of WebApi Which is missing.

    To avoid this problem , 
    Open Package Manager Console and type this in it

    Install-Package Microsoft.AspNet.WebApi.WebHost

    The issue will be resolved. (Don't forget to add the Namespace)

    I hope this post may help you guys.

    Friday 17 April 2015

    could not load file or assembly 'abcd' or one of its dependencies

    I faced this problem in my recent project exception was

    could not load file or assembly 'abcd' or one of its dependencies. an attempt was made to load a program with an incorrect format.

    BadImageFormatException was unhandled:
    Could not load file or assembly 'ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.



    I found out the solution which is not related to the code but it is because, of the assembly or dll.
    My project was built in 64-bit but we had included a dll which was built on 32-bit.

    Therefore, this exception occured to overcome this problem need changes in iis.

    Step  -> 1
    In IIS > select your pool refer below screen shots



    Step -> 2
    Select your application pool and right click -> select advanced settings 



    Step -> 3 
    Change the Enable 32 Bit Applications to True
    Step -> 4
    Restart IIS and check 

    I hope it'll help others who are facing this same issue.

    If you find any others solutions, please post here. 

    ---- Thank you

    Friday 27 February 2015

    Simple Date search in LINQ c#

    The main problem faced in my recent project is the date search in LINQ .

    Generally, Date search we have to check each and every datepart individually.
    Example is mentioned below

    (t.LastModifiedDate.Value.Day >= receivedFromDate.Value.Day &&
    t.LastModifiedDate.Value.Month >= receivedFromDate.Value.Month &&
    t.LastModifiedDate.Value.Year >= receivedFromDate.Value.Year)
    &&
    (t.LastModifiedDate.Value.Day <= receivedToDate.Value.Day &&
    t.LastModifiedDate.Value.Month <= receivedToDate.Value.Month &&
    t.LastModifiedDate.Value.Year <= receivedToDate.Value.Year)


    It will look for individual date part, where code looks very large.


    Therefore, I was searching for other alternative for DateTime search
    then got know about a function which is built in EntityFramework
    System.Data.Entity for version 6 and above

    Function name is DbFunctions 
    Example is shown below


    (DbFunctions.TruncateTime(t.ContractDate)>=
    receivedFromDate.Value)
    &&
    (DbFunctions.TruncateTime(t.ContractDate)>=
    receivedToDate.Value)


    In earlier versions of Entity Framework the function name was


    EntityFunctions.TruncateTime()



    I hope it is very small tip but it may help guys who are needed with.

    Saturday 31 January 2015

    Windows phone 8 XMPP Send and receive message


    Continued from my previous article. Please, find link here.

    Sending XMPP message in windows phone 8 does not require any analysis. Because, it is a method built in with XMPP Client of the DLL.

    Below is the syntax required to be followed for sending message.
    private void SendXmppMessage(String Message, JId ReceiverJid)
            {
                ObjXmppClient.SendChatMessage(Message.Trim(), ReceiverJid);
            }

    But to receive a message from other roster requires handler to initiate the message receiving asynchronously. The handler is OnNewConversationItem.

    Syntax is mentioned below

    ObjXmppClient.OnNewConversationItem += ObjXmppClient_OnNewConversationItem;

    void ObjXmppClient_OnNewConversationItem(RosterItem item, bool bReceived, TextMessage msg)
            {
                if (bReceived)
                {
                    //do your property settings
                }
            }

    If bReceived ==true then message is received from other roster.
    Else then message is sent by you to other roster.

    Note : I am working on sample to send and receive files. I will update it soon.


    It looks so simple to receive message now right? If yes , please, post a response or feedback or any update required.

    I will be hoping to get good feedback and response.

    In my next article, I will help you guys to get chat history from openfire server in Windows Phone 8.

    Thursday 1 January 2015

    Using CTE in sql

    CTE in SQL

    CTE is abbreviated as Common Table Expression.

    CTE holds the query results temporarily later this results set can be manipulated for only next instance. 

    Which means CTE is always followed by any DML i.e., Select,Insert,Update,Delete.
    Only till the execution of the DML CTE will be able to hold the data (query results).

    Please, view the below mentioned sample  with syntax

    with cte as
    (
        Select * from Table1 join Table2 on Table1.ColumnName=Table2.ColumnName

    Select * from cte

    Pass CTE results to other CTE 


    CTE data can be hold and passed to another CTE 

    Example

    with cte as
    (
        Select * from Table1 join Table2 on Table1.ColumnName=Table2.ColumnName
    ) ,

    cte2
    (
        Select * from Table3 join cte on Table3.ColumnName=cte.ColumnName

    select * from cte2



    Increment column value with simple update statement sql

    To increment a column value in sql table with simple update statement is shown below.

    DECLARE @incrementer bigint

    SET @incrementer = 0

    update

    tablename

    set @incrementer = columnname= @incrementer + 1



    This can be achieved even with cursors but we all know the disadvantages of cursors in sql.

    This query works even, if column is NULL.

    This My first information in MyBlog - Krafting DotNet.