Saturday, 9 November 2013

Microsoft sql server error 18456 login failed for user

In this post I will explain about the SQL server error code : 18456 and also will provide the appropriate solution.

Scenario - I was connecting my local SQL server by using SQL authentication. 
                 I got an error code: 18456, refer the below screen shot -



SQL server error: 18456 overview - This error occurs when your authentication request is been successfully accepted by SQL server named, but due to some reason SQL server is not able to grant the access to connect.

Reason - This error reveals that SQL server authentication is not enabled in local server.

To enable SQL server authentication, Follow the below steps

Step 1 - Go to SQL server properties by Right click -> Properties.


Step 2 - Enable SQL server authentication mode.






Step 3 - Restart the SQL server.





Now try to connect using SQL server authentication mode. Hope this will solve your problem.





Thursday, 10 October 2013

SSRS: sorting in data

Question: How to apply sorting on columns in SSRS?
Answer: To apply sorting on columnss in SSRS, there are following steps -

Step 1 - Select whole table, right click on the top-left corner then select tablix properties. 














Step 2 - Once click on tablix properties a dialog will appear, select sorting vertical tab. Add filters by and corresponding order(ascending or descending)as below screen shot.







































I hope it should work.























SSRS: Decimal places

Question: How to remove decimal point in SSRS cell's data?
Answer: In SSRS if it is required to remove decimal point from cell's data then need to set the format of number.

Example - If cells data is having the format like 2034.152. Then it would be 2034 after formatting.

or If cells data is having the format like 2034.652.Then it would be 2035 after formatting.

Follow the below steps -

Step 1 - Go to the cell's expression by right click and select expression.

Step 2 - Do the round of in to expression -









Now check your report preview,  I hope it should work.


Question: How to place two decimal places in SSRS cell's data?
Answer: In SSRS if it is required to place decimal points till two places in cell's data. Then need to set the format for cell's data.

Example - If cells data is having the format like 2034.1. Then it would be 2034.10 after formatting.

or If cells data is having the format like 2034.667.Then it would be 2034.67 after formatting.

Follow the below steps -

Step 1 - Go to the cell's expression by right click and select expression.

Step 2 - Set the format and round of in to expression -










Now check your report preview,  I hope it should work.

Sunday, 6 October 2013

How to pass logged in user name as SqlParameter in ASP.NET

In the scenario i have a gridview, which should contain the data based on current logged in user. The main challenge, i was facing how to pass current login user name to the Sqlparameter. After a little research i got a wonderful solution which is worked - 

Step 1- Defined select parameter in "<asp:SqlDataSource" as 








Step 2- In page load write the below code -















This work perfect for me, Please provide your comment if you got something better.

Monday, 23 September 2013

Question: How to remove white space from a number in excel?

Sometime we got the data in excel sheet in number format which contain space as 1000 separator. This format could cause the problem if you use those excel data further as number in data upload process. In data upload process SSIS package will not work because of set up rules. So at that time we need to remove black space between the numbers. For that follow the below steps -

Step 1 -  Copy the space only after select.
Step 2 - Use substitute method in excel as below screen shot -









Note : In the substitute method, space should be copied(ctrl +C).
I hope this will solve the problem.


Let me know here if anyone have better answer.

Sunday, 15 September 2013

Convert DataTable to List in c#

There is very simple way to convert a datatable into generic list in c#. Have a look at the below steps -

Step 1 - Get the datatable, In my example datatable in containing three columns. Those are Name, Designation and Department.

Step 2 - Add a public class to your solution (Right click and add new items then chose class) to define the properties for the list.

public class PropertyClass
{
    private string name;
    public string Name
    {
        get{return name;}
        set { name = value; }
    }

    private string designation;
    public string Designation
    {
        get { return designation; }
        set { designation = value; }
    }

    private string department;
    public string Department
    {
        get { return department; }
        set { department = value; }
    }
}

Step 3 - Come to the page where conversion is required from datatable to list.
write the similar code as below -
let's say datatable which need to convert to list is dtMain.
   /// <summary>
    /// Method: Convert into list from datatable
    /// </summary>
    /// <returns></returns>
    private List<PropertyClass> GetListfromDataTable()
    {
        DataTable dtMain = GetDataTable();
        //List type object of the property class
        List<PropertyClass> propClass = new List<PropertyClass>();
        foreach (DataRow dr in dtMain.Rows)
        {
            //Object of the propery class
            PropertyClass objPC = new PropertyClass();
            //asign values
            objPC.Name = dr["Name"].ToString();
            objPC.Designation = dr["Designation"].ToString();
            objPC.Department = dr["Department"].ToString();

            //add one row to the list
            propClass.Add(objPC);
        }
        //return final list
        return propClass;
    }

Step 4 - Simple call this method, let's say on pageload
protected void Page_Load(object sender, EventArgs e)
    {
       //get datatable value into list on pageload
        List<PropertyClass> pc = GetListfromDataTable();
    }

Your feedback will be appreciated.

Sunday, 8 September 2013

IIS Manager Error - HRESULT 0X80070020 - THE PROCESS CANNOT ACCESS THE FILE BECAUSE IT IS BEING USED BY ANOTHER PROCESS

In IIS6.1 I was trying to start my Default Web Site and was getting the following error screen.












The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

Above error is coming because default port 8080 is not assigned to system. So default website under IIS manager is not able start. 
To Resolve the above error i followed the below steps, and it worked for me.

Step 1 - Go to run, type cmd, command prompt will appear.

Step 2 - We need to find which process is using the default port 8080. To find this type the below command in your command prompt. "Netstart -ano

It will show the default port is using by using process.




Step 3 - As per above screen the port 8080 is using by the process 3152. Now we need to find which application is assigned for process id 3152.
Type "tasklist /fi “PID eq 3152in your command prompt and see the result.





As per the above screenshot the skype application is using the port 8080. we need to kill skype application manually through task manager. 

Step 4 - Start your default website in IIS manager. It will work.

Please try the above described steps, it worked for me.



Thursday, 11 July 2013

Version History


Version/GenerationRelease TimeDevelopment Enviornment
1.0February 2002Visual Studio .Net
1.1April 2003Visual Studio .Net 2003
2.0November 2005Visual Studio .Net 2005
3.0November 2006Advancing(WPF,Silver light)
3.5November 2007Visual Studio .Net 2008t
4.0April 2010Visual Studio 2010
4.5August 2012Visual Studio 2012


Narrow view of .Net framework























Wednesday, 10 July 2013

Why .Net framework?

Before the time of .Net , Programmers/ Developers are forced to contend with bunch of issues, some of them are following as below –


  • Versioning Problem – No software upgrade
  • No assembly concept -  An ease reusability of the function without calling the code
  • COM services  - only 1% - 5 % com were using mostly for media services, and performance issues.
  • For a simple print ie “Hello world”, this required a lot of coding for the programmers.
  • Application and page life cycle was very rare so handling of page request was challenging task.
  • Microsoft introduced .Net framework as a rescuer.
  • .Net framework is consisting so many features, those are helping to programmers to save the effort and time.
  • Machine independent
  • Language inter-operability
  • Solution of versioning problem
  • Common type system
  • A very big collection of class library
  • Provide Global assembly cache to install MS assemblies
  • User interface design became very simple to manage as MS introduced IDE(Integrated Development Environment)
  • Architectural design of the application
  • Security
  • Consistent object oriented
  • Language Independency
  • Short of code
  • Introduction to mail server
  • Localization and globalization



Related Topic

What is .NET framework?


  1. .Net is not a programming language, it is consisting a set of class libraries and Security mechanism along with a compiler which is know as CLR(Common Language Runtime).
  2. .Net framework is a product of Microsoft, which was first introduced in the late 1990 during next generation window services(NGWS)  development. 
  3. .Net is a programming infrastructure developed by Microsoft  for building, deploying and running the applications.
.Net framework provides following tools for managing user and application interfaces

  • Window form
  • Web form
  • Console Application
  • Web services
These tools enable users to develop user friendly desktop based as well as web based applications using wide variety of languages on the .Net platform.



What was before the .Net framework?

When .Net was not in the market, that was very different time, people use to do development by using –
Windows GUI development - Win32 API, MFC, Visual Basic and Component object model
Web Development – ASP



  • It was really very difficult to the programmer to achieve a good user interface or achieve reusability of functionality through ease of access.
  • People use to do windows based application by using component object model which was causing the performance issue of the application.
  • Those days there were None availability or difficult to access of language inter-operability, versioning , services, machine dependency.
  • Very less classes under MFC library, To make a small logic there was a huge code behind that.
  • Application life cycle and page life cycle was available but with very less features.
  • C and C++ developer are forced to contend with complex memory and pointer arithmetic
  • Most of the Windows application were using COM classes, COM’s language independence is very limited.
  • Programs or application were not independent, Most of the time they were machine dependent.



Related Topic



Wednesday, 12 June 2013

Pivot Example in SQL Server

Hi All, I got the scenario where i need to present the row data as column header in SQL server 2008. My scenario might be bit different. Please have a look.













I need to present the month column data row wise corresponding to all the Fields
([AC_Metrics As Euro],[AC_Metrics As Units],[AC_Metrics As LC],[BD_Metrics As Euro],[BD_Metrics As Units],[BD_Metrics As LC]). According to my requirement data should be appear like -










In the above image, data is same as the original data, but the presentation style of the data has been changed. In the above image all months from the row data became column header and other corresponding details (Euro and Units) became the value(total sum).
So my requirement has been full filled. I tried to pivot the SQL table but in different way. 
I recognized that if there are two column then easily we can do the  pivoting but when there are more than two columns then pivoting might be little bit difficult. 
To implement this scenario i used pivoting after implementing the union and few temporary tables.

Step 1: Get all the data from the original table and insert into a temporary table.
SELECT  * into #Temp1 from YourTable

Step 2: Select required data from the temporary table and implement union as below after that insert this data into an another temporary table -

















Step 3: Declare variables as below - 
     DECLARE @cols AS NVARCHAR(MAX),
    @query  AS NVARCHAR(MAX)

 Step 4: Assign the value to @cols and @query 
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(MonthYear) 
                    from #Temp2
            FOR XML PATH(''), TYPE
            ).value('.', 'NVARCHAR(MAX)') 
        ,1,1,'')
        
set @query = 'SELECT' + @cols + '
            from 
            (
                select MonthYear,Amount
                from #Temp2
            ) x
            pivot 
            (
                max(Amount)
                for MonthYear in (' + @cols + ')
            ) p '


Step 5: Execute the query and drop the temporary tables
execute(@query)     
drop table #Temp1
drop table #Temp2


In this way i got the result for the required scenario.






Tuesday, 11 June 2013

wcf from jquery

Here I am assuming that readers already aware about How to create and publish a WCF service. As per the managing the data, There are two types of scenario  through WCF too.

1. Get (fetching the data) operation 
2. Post (insert, update and delete) operation

Here We will check both the scenario one by one respectively.

1. Calling a WCF service by using JQuery and perform data pulling (Get Operation)

Step 1At first we need to add a JQuery class library, which will take all the basic references.

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>

Step 2: We just suppose to call a WCF service on the page load, or else you can call it on other 
           event handler like button click, change Index ...so on.

$(document).ready(
     function () {
     });

Step 3: Call a WCF through AJAX call.
     $.ajax({
             //Mention the operation type GET as data is pulling from the server
             type: "GET",
             //Content type sent to the server
             contentType: "application/json; charset=utf-8",
             //Expected result format form the server
             datatype: "json",
             //Pass the url to the service
             url: "http://localhost:8082/SampleWCF.svc/fetch?Id=10",
             beforeSend: function (req) {
                 //Show some progress bar image
                 //Do some validation like authentication(this is optional)
             },
             success: function (result, textStatus) {
                 //Hide the progress bar image
                 //Check if result is null
                 if ((result.d == null && jQuery.parseJSON(result).d.length > 0) || (result.d != null && result.d.length > 0)) {
                     //Show message for no record found
                 }
                 else {
                     //Fetch the result
                     alert(result);
//Or if result is a container then we can find the result by index also
alert(result.d[0].key; //Where key is nothing but name of the field
                 }
             }
         });

2. Calling a WCF service by using JQuery and perform data pushing (Post Operation)

Step 1 and step 2 will be same as described above

Step 3:
// Make a data set (which is required for the pushing)
var data = _EventSessionDS.data();

Step 3:

Call a WCF through AJAX call.
     $.ajax({
             //Mention the operation type GET as data is pushing to the server
             type: "POST",
             //Content type sent to the server
             contentType: "application/json; charset=utf-8",
             //Expected result format form the server
             datatype: "json",
            // If there is no need to process the data before send
            processData: false,
             //Pass the url to the service
             url: "http://localhost:8082/SampleWCF.svc/Push?Id=10",
            //Convert java script value to JSON 
            data: JSON.stringify({ pSessionsItem: data }),
             beforeSend: function (req) {
                 //Show some progress bar image
                 //Do some validation like authentication(this is optional)
             },
             success: function (result, textStatus) {
                 //Hide the progress bar image
               //show the success message
             }
         });

Delete scenario:
if we need to delete the data by calling a WCF service through JQuery then we need to just remove the data set and data from the above code.
var data = _EventSessionDS.data();
data: JSON.stringify({ pSessionsItem: data }),



Thursday, 6 June 2013

c# - uploading image to azure blob storage

To upload an image to the blob storage for further use, we will call a WCF service method by an Ajax call that returns the unique blob name as result. After that we will render the image into an html control for checking.
Please follow the below steps –

Step 1: Create a WCF method for uploading the image into the blob storage
public String ClientUpload()
        {
            // Declare a variable for holding the blob name
            String tUniqueBlobName = null;
            //Authanticate the user and get the Client Id Let’s say this is ClientId
            try
            {
               // initialize queue storage
               CloudBlobContainer tblob = StorageBlob.GetBlob(StorageBlob.Blobs.fileupload, ClientId);
              // Create a unique file name
               String tUniqueBlobName = string.Format("File_{0}.{1}", Guid.NewGuid().ToString(),        HttpContext.Current.Request.Files[0].FileName.Split('.').Last());

             // Get the blob
            CloudBlockBlob tBlob = tblob.GetBlockBlobReference(tUniqueBlobName);
            tBlob.Metadata.Add("OriginalName", HttpContext.Current.Request.Files[0].FileName);
            tBlob.Metadata.Add("FileExtention",   
            HttpContext.Current.Request.Files[0].FileName.Split('.').Last());
            tBlob.Metadata.Add("UploadedByRecId", pUser.Id.ToString());
            tBlob.Metadata.Add("UploadedByName", pUser.Name);
            tBlob.Metadata.Add("OwnerCompany", pClientId.ToString());
            //ObUser -  User’s object
                tUniqueBlobName = UploadToBlob(ClientId, ObUser);
            }
            catch (Exception ex)
            {
            //show the error
            }
            return tUniqueBlobName;
        }

 Step 2: Create html controls for holding and uploading the image

<div id="divPreview" class="divFrame">
                   </div>
                   <div class="DivButton">
                       <span id="ChangePhoto">Change</span>
//Create a control for image upload and set the display none.
                   <input id="inputUploadFile" name="inputUploadFile" type="file" multiple="false" accept="image/*" style="display:none;" />
</div>

Step 3: On page load of javascript initialize the Upload File control
$(Document).ready(function(){
//Call a method for initialize the file upload control
InstanciateFileUpload();
});
//------------------------------------------------------------------------------------
// Define the initialize file upload method
//------------------------------------------------------------------------------------
function InstanciateFileUpload() {
    $("#inputUploadFile").fileupload({
        limitMultiFileUploads: 1, //set the file upload limit
        replaceFileInput: false,
        dataType: 'json',
        url: _WebServiceAddress + "FileImport/ClientUpload", //WCF service method
        change: function (e, data) {
            if (e.target.files.length > 1) {
//show the error message file cannot be uploaded more than one
            }
        },
        beforeSend: function (req) {
//Do some validation if you want before sending the request
        },
        add: function (e, data) {
            // When a file is added to the upload queue, get a reference to the xhr
            jqXHR = data.submit();
        },
        start: function (e, data) {
            $("#previewProgress").show(); //show the progress image
        },
        done: function (e, data) {
            // Launch preview
            var tImageName = jQuery.parseJSON(data.jqXHR.responseText);
            RenderPreview($("#divPreview"), tImageName, true); //render into html conrol 
        },
        fail: function (e, data) {
            $("#previewProgress").hide(); //Hide the progress image
//Show some failure error message
}
    });
}
Step 4 -  Create a button click event handler for Change the profile picture
//event for change and remove photo
    $("#ChangePhoto").on("click", OnChangePhotoButtonClick);
//Define the method
function OnChangePhotoButtonClick(e) {
    $("#inputUploadFile").click();
}

That is it. Please follow the above steps, it should work.