Thursday, February 20, 2014

Getting no results in pass through sql when a date is specified

I have a SQL query like this:
SELECT * FROM tableName
WHERE DocDate BETWEEN str(StartDate) AND str(EndDate)

I'm passing this in using pass through SQL, but it's not getting results... Copying and pasting this exact SQL query into SSMS shows that there are results for it. So what's the problem?

It turns out, you can't just pass a date to SQL Server using the str() function. You have to use sqlDate() instead.

So the query above becomes:
SELECT * FROM tableName
WHERE DocDate BETWEEN sqlDate(StartDate) AND sqlDate(EndDate)

If only I had to known this before wasting 4 hours of my life, wondering why a simple query was not working.


Tuesday, February 18, 2014

Powershell oddity with formatting strings

I executed this:
"{0:C}" -f 120*500000

This is what I thought this was equivalent to:
String.Format(“{0:C}”, 120*500000)

Here’s what it really did:
Printed $120 500000 times. I think that means it did this:

new string(String.Format("{0:C}", “120”), 500000)
which is sorta equivalent to this:
For(int i = 0; I < 500000; i++)
String.Format("{0:C}", “120”);

I know the multiply operator is overloaded for strings, so
"120"*5 would be equivalent to new string("120", 5). 

So this must be order of operations weirdness and implied parentheses, like
"{0:C}" -f 120*500000 == ("{0:C}" -f 120)*500000

It would make much more sense if it implicitly grouped everything AFTER the -f flag together into a subexpression, in other words:
"{0:C}" -f 120*500000 == "{0:C}" -f $(120*500000)

What i had to do to get the desired behavior was this:
 "{0:C}" -f $(120*500000)

Doesn't make sense to me that i would have to wrap that in a subexpression. Should be implicit.

Monday, February 17, 2014

Certificate error in Exchange 2010 integrated with Lync Server

1. Incoming calls suddenly started to fail
2. Outgoing calls still worked

When looking in the event log on the Exchange server i see: "A TLS failure occurred because the target name specified in the certificate isn't correct." (then the name is an empty string "")
Event 1021

When restarting the UM service I see another warning message, "The UM IP gateway or host "" resolves to an invalid FQDN. Please check your UM IP gateway and DNS server configuration.

The second warning message is much more indicative of the problem. It can't find the hostname based on the IP Address. So i add it to the hosts file, restarted the UM service, and it worked.

Note: Updating the DNS would also work.

The WS-Management service cannot process the request on Exchange Server

Trying to connect to the Exchange Console, getting an error message:
"...The WS-Management service cannot process the request..."

Restart the MSExchangePowerShellAppPool IIS app pool

This can done through the IIS Manager or with these two lines in powershell:

Import-Module WebAdministration
Restart-WebAppPool MSExchangePowerShellAppPool 

Thursday, February 6, 2014

unable to copy file from obj to bin in Visual Studio

Put this in your project Build Event's pre-build event command line:

if exist "$(TargetPath).locked" del "$(TargetPath).locked"0
if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"


Saturday, February 1, 2014

Threading in C#

I need a refresher on threading for a project I'm doing. Here's a good resource

There was an error in this gadget