Tuesday, September 29, 2015

It doesn't always needs to be a complicated solution... EWS “The request failed. The remote server returned an error: (401) Unauthorized"

After following this MSDN article about configuring impersonation for EWS. I was ready to go test my newly created user with impersonation rights. I already had an other account with impersonation rights which worked just fine with the following piece of code.

 Try  
      Dim svc As New ExchangeService()  
      svc.Url = New Uri("https://outlook.office365.com/EWS/Exchange.asmx")  
      svc.Credentials = New WebCredentials("svc_user@domain.com", "xxxx")   
      svc.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "peter@domain.com")  
      Dim mail As New EmailMessage(svc)  
      mail.From = "peter@domain.com"  
      mail.Subject = "Test Peter svc user"  
      mail.Body = "Test Body"  
      mail.ToRecipients.Add("tom@domain.com")  
      mail.Save()  
      mail.SendAndSaveCopy()  
 Catch ex As Exception  
      MsgBox(ex.ToString)  
 End Try  

But with my newly created svc_user I kept getting the following error: "The request failed. The remote server returned an error: (401) Unauthorized". Enabling the traces on my service calls gave no extra info. After googling this error I found a lot of MSDN pages with a lot of different possible solutions, but all to no avail.
After a tip from a colleague I did what I should have done a lot sooner. Navigate to https://portal.office.com and tried logging in with the svc_user. I got nice clear message stating that my password had expired or that I should change my password on first usage. After doing this everything worked just fine and I felt a bit dumb for spending a couple of hours on this issue :-)

Saturday, September 26, 2015

Getting started with SQL

If your looking for an interesting course to start learning SQL this might be it. Courtesy of codecademy
https://www.codecademy.com/courses/learn-sql

Edit 06/06/2016

another nice resource is

Wednesday, September 16, 2015

SQL Server triggers, how to only log rows where values have actually changed.

In SQL Server inside a trigger if you want to check if a row has actually changed, you would think you could use COLUMNS_UPDATED but this only returns which columns are included in an update statement. It doesn't check if the actual values changed. A nice solution I've found is to make use of the SQL EXCEPT operator and a CTE. Here's a sample that you may find useful.


 ...  
 FOR UPDATE  
 AS  
 declare @rijen int  
 ;with ChangedData as   
      (  
      select deleted.column1, deleted.column2, deleted.column3, deleted.column4 from deleted  
           except  
      select inserted.column1, inserted.column2, inserted.column3, inserted.column4 rom inserted  
      )  
 select @rijen = count(*) from ChangedData  
 if @rijen > 0  
 begin  
 ...  
 end