Fransiscus Setiawan | EV Charging & Azure Solution Architect | Sydney

Technical Insights: Azure, .NET, Dynamics 365 & EV Charging Architecture

Web Service Tester

This is an application to access your Web Service/API without worrying to create your own client application for the sake of testing. Personally, I’m using soapUI (an open source application to test web service)

http://sourceforge.net/projects/soapui/files/

I’d prefer to use tool this because it provides you a transparent communication between the client and the Web Service and it’s really simple to use and configure. It’d save you a lot of time to debug the issue for your client. You can trace it down whether the issue is in the client or in the web service itself

Profiling CLR for .NET application

CLR Profiler can be used to analyse how your object is allocated in memory and which object has taken the most memory. It also can be used to detect memory leak

To download CLR profiler for .NET 2.0 please visit http://www.microsoft.com/download/en/details.aspx?id=13382 , there is another version for .NET framework 1.1

-Extract the file into your desired location

-you also need to run “regsvr32 ProfilerOBJ.dll” otherwise you will get dialog message that mentioned it’s waiting for the CLR and you will not get any result

– Run the CLRProfiler.exe in Binariesx86 if your app is 32 bit and Binariesx64 if your app is 64 bit

For profiling windows app, you can do the following steps:

1. Select the exe file

2. Do stuff/interact with your application

3. Once you are finished then you can close your application or select “Kill Application”

4. Upon completion it will give you the screen below

For profiling ASP.NET app, you can do the following steps:

1. Select Profile ASP.NET from file menu

2. It will restart your IIS with the necessary trace

3. Select “Start ASP.NET”

4. Once you are finished then select “Kill ASP.NET”

5. It will restart the IIS and remove the trace added before

6. Upon completion it will give you the screen below

*You can use this for service as well –

This is the information for GC

Remapping svc extension in IIS 7 extension handlers

If you open your WCF/ svc file in your localhost through browser and it just display blank page then what might happen is you don’t have handler associated with svc extension

To verify it, go to your IIS and go to IIS Handler Mappings and try to find an svc extension entry, but if you couldn’t find extension SVC exists on the list, then you can remap/re-add the svc extension by running

C:\Windows\Microsoft.NET\Framework64\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i

*if you are still using 32 bit then you just need to replace Framework64 with Framework

SQL Statistical information – Index usage, etc and also tips on how to find the most costly SQL Server queries using DMV’s

This is just an information for the users that might not know this feature in SQL Server Management Studio, eventhough I’m sure most of people should have known this feature

Basically SQL Server stores all the database usage information including index usage, disk usage, top transaction etc. *This information is not available from the backup file

1. Right click your database, Go to Reports, Go to Standard Reports and you can find all the out of the box reports

Clicking one of the report will give you detailed information – in this sample, I’m using Index Usage Statistics

How to find the top 20 most expensive queries by the total execution time, run this query against the database

SELECT TOP 20
 qs.sql_handle,
 qs.execution_count,
 qs.total_worker_time AS Total_CPU,
 total_CPU_inSeconds = --Converted from microseconds
 qs.total_worker_time/1000000,
 average_CPU_inSeconds = --Converted from microseconds
 (qs.total_worker_time/1000000) / qs.execution_count,
 qs.total_elapsed_time,
 total_elapsed_time_inSeconds = --Converted from microseconds
 qs.total_elapsed_time/1000000,
 st.text,
 qp.query_plan
FROM
 sys.dm_exec_query_stats AS qs
 CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
 CROSS apply sys.dm_exec_query_plan (qs.plan_handle) AS qp
ORDER BY qs.total_worker_time DESC

-It will give you this result set

– Clicking the query_plan will give you detailed query plan

Usage of Pivot in SQL Server

The usage of PIVOT keyword

In SQL Server we can transform a horizontal rows to be vertically represented by using Pivot Keyword

Run this query to have sample data

CREATE TABLE OrderItems(Order_No INT, ProductName VARCHAR(255), TotalQty INT)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (112, ‘Sprite’, 5)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (112, ‘Coke’, 7)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (112, ‘Lemonade’, 2)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (113, ‘Apple Juice’, 8 )

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (113, ‘Diet Coke’, 2)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (114, ‘Coke’, 15)

GO

INSERT INTO OrderItems(Order_No, ProductName, TotalQty)

VALUES (114, ‘Lemonade’, 13)

GO

Running simple select from OrderItems will give you this table

Now we want to look it statistically – maybe for reporting purpose. Run the query below

SELECT Order_No, Sprite, Coke, Lemonade, [Apple Juice], [Diet Coke]

FROM (

SELECT Order_No, ProductName, TotalQty

FROM OrderItems) ItemList

PIVOT (SUM(TotalQty) FOR ProductName IN (Sprite, Coke, Lemonade, [Apple Juice], [Diet Coke])) AS PivotResult

ORDER BY Order_No

GO

It will give you this result set

Simple Collapsible Panel using JQuery

I found a simple collapsible panel developed by a guy called Darren Ingram and I’d definitely recommend it to anyone wanted to implement collapsible panel. His Jquery implementation of collapsible panel is very simple. It just need 2 files (diQuery-collapsiblePanel.js and diQuery-collapsiblePanel.css – where the css classes can even be integrated to your own css class). I prefer this implementation because it’s just a div implementation and the JQuery script will be hooked up to the div elements (where the class name is collapsibleContainer) upon the page loaded. Simple and lightweight in comparison to the collapsible panel of AJAX toolkit (http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CollapsiblePanel/CollapsiblePanel.aspx)

the source code for the collapsible panel by Darren Ingram can be downloaded from his website (http://www.darreningram.net/pages/examples/jQuery/CollapsiblePanelPlugin.aspx)

Fransiscuss.com is back

After a few months, my website has been down because of someone from Tunisia was proudly hacking my website for his glory without thinking the impact to someone else. well anyway, life goes one and I forgive him regardless. I’ll start writing a few articles in the next few weeks of Message broker in SQL Server, Dependency Injection, and Thread pooling.

Using Disposable object

First method is to use the “Using” keyword which is quite clean and simple

using (IDisposable obj = new DataTable())

{

//do your logic with obj variable

}

Second method is to use Try and finally keyword

IDisposable obj = null;

try

{

obj = new DataTable();

}

finally

{

if (obj != null)

{

obj.Dispose();

}

}

Remove UTF8 BOM Character from the file

Normally when you have a UTF8 encoded file then it might have BOM character that will be rendered when you read it using filestream even though when you open the file with the notepad it doesn’t have that character.

I’ve created a function to remove the BOM character from the file

private void removeBoms(string filePattern, string directory)

{

try

{

foreach (string filename in Directory.GetFiles(directory, filePattern))

{

var bytes = System.IO.File.ReadAllBytes(filename);

if (bytes.Length > 2 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)

{

System.IO.File.WriteAllBytes(filename, bytes.Skip(3).ToArray());

}

}

MessageBox.Show(“Files have been processed completely!”);

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

//uncomment this for recursive

//foreach (string subDirectory in Directory.GetDirectories(directory))

//{

//    removeBoms(filePattern, subDirectory);

//}

}

How to call it

private void btnProcess_Click(object sender, EventArgs e)

{

string extension = txtExtensions.Text;

if (extension.Trim().Length > 0 || folderBrowserDialog1.SelectedPath.Trim().Length > 0)

{

if (!extension.StartsWith(“*.”))

{

extension = “*.” + extension;

}

//just process the html files

removeBoms(extension, folderBrowserDialog1.SelectedPath);

}

else

{

if (extension.Trim().Length == 0)

{

txtExtensions.Focus();

MessageBox.Show(“Please specify the extension files”);

}

else if (folderBrowserDialog1.SelectedPath.Trim().Length == 0)

{

MessageBox.Show(“Please select target folder”);

}

}

}

Javascript Decode/Encode unicode character (IE)

Simple function to encode and decode UTF8 character for unicode (this is for IE)

Encode

utf8bytes= unescape(encodeURIComponent(unicodecharacters));

Decode

unicodecharacters= decodeURIComponent(escape(utf8bytes));

Page 9 of 19

Powered by WordPress & Theme by Anders Norén