Extract url / adress from hyperlink cell in Excel

1. Go to Visual Basic for Applications module by clicking Alt+F11
2. Create new Module by Insert->Module
3. Create a simple function in the newly created module
Function GetCellUrl(LinkCell as Range)
   If LnkCell.Hyperlinks.Count = 0 Then
      GetCellUrl = ""
   Else 
      GetCellUrl = LnkCell.Hyperlinks(1).Address
       End If


     End Function

SQL - How to delete table content quickly

The deletion of table content may take significant amount of time when the number of rows is large. This is so because every singe row deletion is logged into the database transaction log.
In the cases that the deletion log is not important you can simply remove the data rows w/o logging any individual row deletion by truncating the table:

TRUNCATE TABLE [TableName]


Reference:
http://msdn.microsoft.com/en-us/library/ms177570.aspx

100% CPU usage by SQL Server - Look for Active (running) SQL queries

I found a very useful posts regarding analysis of currently running SQL queries and high SQL server load in Pinal Dave's blog.

http://blog.sqlauthority.com/2009/01/07/sql-server-find-currently-running-query-t-sql/

http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/

Using these tricks the culprit of the high load can be easily indicated.

Until the problem resolution is implemented KILL [session_id] can stop the problematic query w/o server restart or long waiting.

Windows 7: How to access password protected shared folder

How to pass current Windows credentials to password protected network share

1. Create user/password on destination computer matching the user/password of current computer
2. Share a folder on the destination computer giving access to the new created user
3. On current computer change the local security settings as following:
3.1 Open Local Security Policy Console
3.2 Select Local policies -> Security Options -> Network security: LAN Manager authentication level
3.3 Select Send LM and NTLM response and click OK.


You can also specify different user to connect by during mapping a network drive on the destination computer.

IIS Redirection with Page and Query String (UPDATED)

By default IIS redirects to a given domain and/or application.
The web page and query string can be transferred to the destination url by using the respective parameters $S and $Q.

Ex.
template: http://example.com$S$Q
redirection from
http://old-example.com/default.aspx?id=1
will lead to
http://example.com/default.aspx?id=1

In IIS 6 the checkbox "Exact Url" will avoid appending the web page to the query string.

UPDATE:
In order to achieve that behaviour in IIS 7 you have to first enable "Redirect all requests to exact destination" and append the sufix $S$Q to the url.
If you rely in the automatic url redirection of IIS (by default, w/o $S$Q in url) the query string is actually cut.

How to share Windows 7 folders with anonymous access including registry fix

I found very interesting forum thread describing how to share Windows 7 folder to other machines without password protection. It includes a few registry tricks to unlock that feature, that might had been set by Anti-virus software. http://www.acryan.com/forums/viewtopic.php?f=41&t=2269

How to concatenate row data into string using SQL

Very simple way to achieve this is to use FOR XML statement. The result of the following example is list of user names including first and last name separated by commas.

SELECT FirstName+' '+LastName+', ' FROM UserProfile FOR XML PATH('')


But the result string ends with a comma and space. We can either remove it by SUBSTR or REPLACE functions. Using REPLACE as it is shown below saves the usage of subquery or calcualtion of the length of the same expression.

SELECT
REPLACE((REPLACE((REPLACE(
(SELECT FirstName+' '+LastName FROM UserProfile FOR XML PATH('A'))
,'</A><A>',', '))
, '</A>',''))
,'<A>','')


Here is another way to achieve this which might be convinient in stored procedures.

DECLARE @Names VARCHAR(8000)
set @Names=''
SELECT @Names = @Names + CASE WHEN @Names<>''
THEN ', ' ELSE '' END + Name
FROM Users
SELECT @Names

How to use Visual Studio build events to copy output file to multiple destinations (projects)

Calling predefined batch file:
call MyBatchFile.bat

using command line macros:
Ex. copy "$(TargetDir)*.*" "$(SolutionDir)sitename\Bin"

list of macros find here:
http://msdn.microsoft.com/en-us/library/vstudio/42x5kfw4.aspx

Solution on "HTTP Error 414 Request URI too long" error using getJSON

The explanation of 414 error is described here:
http://support.microsoft.com/kb/248061

With regard to JSON queries with jQuery this basically means we are not able to use long GET parameters. But for sure this is necessary for sending bigger objects serialized as JSON.
The solution would be using POST requests, but is jQuery support that?

The answer is yes if we just extend jQuery with post requests as it is described in jQuery forum:
http://forum.jquery.com/topic/getjson-using-post

jQuery.extend({
postJSON: function( url, data, callback) {
return jQuery.post(url, data, callback, "json");
}
});

Then just replace getJSON with postJSON where it is needed.

IIS Url Rewriting - avoid repeat of querystring parameters

Using the URL rewriting mechanism of IIS causes repeat of querystring parameters on every postback, because it builds the postaback url (rewrites url) by appending the querystring to current url.

Actual url:
/product.aspx?type=hats

Rewritten url:
/product/hats

Rewritten url after postback:
/product/hats?type=hats
which is actually equal to /product.aspx?type=hats&type=hats
So the type value is "hats,hats".

To avoid repeat of querystring variables simply check if the url is already rewritten:

protected void Page_Load(object sender, EventArgs e)
{
if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
{
form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
}
}

Detailed description:

SQL Server Express and IIS: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path.

SQL Express user instancing fails with the default IIS 7.x configuration. To solve this you can do the following:

1. Create new application pool in IIS
2. Open Application Pool Advanced settings
3. Change Identity from ApplicationPoolIdentity to NETWORK SERVICE and confirm
4. Change the application pool that the web application belongs to by opening Advanced setting of the web application

3 ways to get date in SQL without time

Here are 3 ways of getting date-only part of timestamp in SQL Server:

1. DATEADD( DAY, 0 , DATEDIFF(DAY,0, CURRENT_TIMESTAMP) )

2. CONVERT( datetime, FLOOR(CONVERT(float(24), GETDATE())) )

3. CAST( CONVERT(CHAR(8), GETDATE(),112) as DATETIME)

Strip time from javascript date object

Setting up the hours to zero does the trick:

var myDate = new Date(); //current date and time
myDate.setHours(0,0,0,0);

Passing Parameters to .NET Web Service as a Query String (GET Method) or POST Request

First of all the way of passing parameters must be defined in web.config as follows:

<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>


Then the URL of the web service may include parameters as query string.
http://tempuri.org/webservice.asmx/MethodCaseSensitive?parameter1=yes&parameter2=123

MethodCaseSensitive is the name of web method to be performed as part of the webservice called webservice.asmx.


In case you need POST method of sending parameters just use a form and text fields as in the following example:


<form name="input" action="http://tempuri.org/webservice.asmx/MethodCaseSensitive" method="post">
<input name="parameter1" type="text">
<input name="parameter2" type="text">
<input value="Submit" type="submit">
</form>

Both of methods return XML response as it is defined in the web method.

The Web Service results can be easily checked using the .NET ability for integrated passing of parametersin a web interface:
http://tempuri.org/webservice.asmx?op=MethodCaseSensitive

The screen allows the user to enter web service parameters and submit them. The result is the same.

ASP.NET Page Life Cycle, event order, master page, page and control events order


    PAGE: Page.OnPreInit()
        USER CONTROL: UserControl.OnInit()
MASTER PAGE: MasterPage.OnInit()
    PAGE: Page.OnInit()
    PAGE: Page.OnInitComplete()
    PAGE: Page.OnLoad()
MASTER PAGE: MasterPage.OnLoad()
        USER CONTROL: UserControl.OnLoad()
    PAGE: Page.OnLoadComplete()
           Page Event Handlers
    PAGE: Page.OnPreRender()
MASTER PAGE: MasterPage.OnPreRender()
        USER CONTROL: UserControl.OnPreRender()
    PAGE: Page.OnPreRenderComplete()
    PAGE: Page.OnSaveStateComplete()
        USER CONTROL: UserControl.OnUnload()
MASTER PAGE: MasterPage.OnUnload()
     PAGE: Page.OnUnload()

More information here:
ASP.NET Page Life Cycle