Saturday, 28 February 2015

Red Gate SQL Prompt - Extend trial period for free

Get to user the full features of SQL Prompt for free?

This is a free little secret to extend the trial period of Red Gate SQL Prompt. Here you are given a new serial key. You will get to use the full features of the tool for another 14 days for free. After the second trial is over you can again attempt to use the technique to extend trial period again.

In SQL Server Management Studio, goto menu SQL Prompt -> Help -> Enter Serial Number. On the "Activate SQL Prompt" window, in the Serial number textbox enter the below text
I need more time
and click Activate button.



Your trial period is now successfully extended.

Tuesday, 24 February 2015

Distinguish between USB2.0 and USB3.0

The easiest way to make out if the USB port on your laptop is USB 2.0 or USB 3.0, is to follow conventions. There are universal conventions followed by all hardware manufacturers that help you to tell which ports on your computer is 2.0 and which one is 3.0.

Facts: USB 3.0 is 10 times faster than USB 2.0, because it uses a technology called SuperSpeed.
Because of this USB 2 is called High Speed adn USB 3 is called SuperSpeed. This is also evident in the symbol used for USB 3 which has SS as part of the Symbol.

Below are the symbols for USB 2.0 and USB 3.0. You can check for these symbols near your laptop USB ports. You make out USB 2.0 and USB 3.0 by:
1) USB 2.0 port symbol is different from USB 3.0 symbol.
2) USB 3.0 port might have a blue tab in the ports
Either one of the above conventions would be used on your device.


USB 2.0 Symbol
USB 3.0 Symbol








USB 2.0
USB 2.0


USB 3.0

USB 3.0

Saturday, 31 January 2015

ASP.NET C# - How to specify File Path

If you want to access a file with in an ASP.NET Application, you should specify the relative path to the file from the application root.
For example your file name is "StockConfig.xml" and its placed within a "Configs" folder.
Now you need to load the file; use the below code for this.
Server.MapPath("~/Configs/StockConfig.xml")
example usage:
xDoc.Load(Server.MapPath("~/Configs/StockConfig.xml"));
Here Server.MapPath, returns the physical path corresponding to the relative path you mentioned.
"~" specifies the application root. So any path you mention following "~" is relative to the application root folder.

In case you are trying to access "Server.MapPath()" from a class library, you will need to "Add Reference" System.Web assembly to your class library and use the code as below:
System.Web.HttpContext.Current.Server.MapPath("~/StockConfig.xml")

Thursday, 16 October 2014

Windows Phone - Load Images from Web Url

You can load an image from the internet and display in your Silverlight Windows Phone Application.
The C# code is:
Uri uri = new Uri("http://Habeeb.in/pic.jpg", UriKind.Absolute)
image1.Source = new BitmapImage(uri);
Happy coding....

Tuesday, 30 September 2014

SQL Server - Group DateTime by Minutes / x minutes

If you want to group by records based on Minutes use the below Group By:
GROUP BY
DATEPART(YEAR, SUB.[SubOnDate]),
DATEPART(MONTH, SUB.[SubOnDate]),
DATEPART(DAY, SUB.[SubOnDate]),
DATEPART(HOUR, SUB.[SubOnDate]),
DATEPART(MINUTE, SUB.[SubOnDate])

If you want to group by records by x minutes, it is as below. In the sample below its grouped by every 10 minutes. so records within each 10 minutes will be in the same group.
GROUP BY
DATEPART(YEAR, SUB.[SubOnDate]),
DATEPART(MONTH, SUB.[SubOnDate]),
DATEPART(DAY, SUB.[SubOnDate]),
DATEPART(HOUR, SUB.[SubOnDate]),
(DATEPART(MINUTE, SUB.[SubOnDate]) / 10)

Monday, 22 September 2014

How to generate web service from wsdl file

This is a common scenario faced by developers who do web service based integrations. The partner if its an external company, might send over the wsdl file and ask to create a web service out of it so they can consume your webservice.

This is when the partner demands more control and they want to make sure all their partners host similar webservices so that the partner's code for the web service call is consistent.

Now to solve the matter, we do not have a GUI genie (wizard) for our help. We will have to do each step manually taking help of command line.

Here are the steps:
1) From the WSDL file create an Interface class using wsdl tool. For this, bring up the Visual Studio Command Prompt Window and run the below command.
wsdl.exe yourFile.wsdl /l:CS /serverInterface
Note: You can decide the language of the Interface Class generated. In parameter /l, use VB or CS for your Visual Basic or CSharp respectively. Finally the command will create a new .cs or .vb file.

2) Create a new .NET Web Service (.asmx).

3) Import the file created in the above step into your project.

4) In your .asmx.cs file in Code-View, modify class as below to implement the interface generated in the above step:
public class MyWebService : System.Web.Services.WebService, IWsdlService
{
// Web methods and other calls goes here....
}
5) Implement the methods mentioned in the Interface class. Finally your webservice class will be something like this:
public class MyWebService : System.Web.Services.WebService, IWsdlService
{
[WebMethod]
public string MyWeMethod1()
{
// your business logic goes here...
return "MyWeMethod1 Result";
}
[WebMethod]
public string MyWeMethod2()
{
// your business logic goes here...
return "MyWeMethod2 Result";
}

Tuesday, 16 September 2014

Javascript - How to check if a string contains another string

String function indexOf returns the position of the sub string in a string. If it doesn't find an occurance of the sub string, it will return -1.
var mainText = "microsoft";
var isSubstring = mainText.indexOf("soft") > -1
alert(isSubstring);
In the example, it checks for the substring "soft" within the main string "microsoft". As it find "soft" inside "microsoft", mainText.indexOf("soft") evaluates to 5 and isSubstring will be true;