Codepolice

Random posts from Ola in English. Mainly about programming and the web.

MS SQL: Saving changes is not premitted if the table need to be re-created

This is a classic. Microsoft SQL Server 2008 introduced a feature that prevents you from changing a table in the designer if it need to be re-created. And whenever i get this i always forget where to turn this feature off. This time i recorded a 14 sec video that shows where this option is. Enjoy :)

Using external SMTP server to send mail via diffrent addresses in Gmail

There is an awesome feature in Gmail that makes it stand out from many other webmails and it’s that you can specify a external SMTP server so that you can send mail from other e-mails. I understand this is a advanced feature that not so many people use but it has an major flaw.

If you change your password on the account that you use to login to your external SMTP server your mails will not be sent. And that is of course fine but the scary part is that you wont get any form of error or notifications that this happened.  Hopefully Google will fix this soon and give us an error when it can’t login to the SMTP Server.

Issues when you upgrade WordPress plugins and core on ISS 7.5

I have had lots of issues with upgrading WordPress plugins and the core WordPress engine on my IIS 7.5 server. The problem has been that you try to upgrade the plugin, you get a fail notice AND the plugin is simply disabled and you loose permission to the folder where the plugin was located. Then you must wait for a couple of hours until you can reinstall the plugin.

When you Google this you find post after post suggestion you to add IUSR users and stuff and give them write permission and while you probably have to to that it was not what was causing this issue.

The problem is the WinCache plugin that IIS use to do some caching stuff with PHP. I finally found this thread that explains the issue and point you to a upgraded version of the PHP extension.

After installing that new DLL everything worked as expected for me at least.

SEO: How the Panda update affected AlternativeTo

This Monday (April 11 2010) we noticed a sudden drop in traffic from Google.com on AlternativeTo.net. Me and my collegaue have tried to figure out why all week and finally we found the answer. In the Google Webmaster Blog there is a post about how Google is deploying it’s new spam filter (named “Panda”) to all English speaking markets. And that should have been a good thing for AlternativeTo because when the filter was introduced on the US market we noticed a 10% growth in traffic from Google.com. But there is ups and downs with this blog post.

In addition, this change also goes deeper into the “long tail” of low-quality websites to return higher-quality results where the algorithm might not have been able to make an assessment before. The impact of these new signals is smaller in scope than the original change: about 2% of U.S. queries are affected by a reasonable amount, compared with almost 12% of U.S. queries for the original change.

And yes, we noticed this and we are now back on almost the same traffic as before the introduction of “Panda”. And I guess this is a good thing. We gained a positive effect when the filter was introduced the first time. Now they have trimmed the filter and it’s probably filtering out some really bad sites and we have maybe gained 1-2% more traffic from Google (it’s hard to measure such low percentage compared to natural changes from day to day and so on).

Here is a little graph from Analytics that is Google.com traffic from US visitors.

Use your IIS logs with WCAT

I just want to write this down so i do not forget it. I found this article that describes how to convert your IIS logs to a script that you can run with WCAT.

http://theether.net/kb/100128

I had to change the HOST header to the script that was generated. And as you can see you can add any header you like to the default section at the top of the script.

 
setheader
 {
 name    = "Host";
 value   = "my.domain.com";
 }
 
setheader
 {
 name="Accept-Language";
 value="sv-se,en-us;q=0.7,en;q=0.3";
 }

Signing a request to setup a custom Amazon CloudFront Distrubution with C#

I love most of Amazons Web Services (AWS). CloudFront is their CDN service and they have a awesome feature that lets you host your files on your own server and then Amazon automatically grabs the files from your server and put them on their CDN. This makes it possible to easily modify your files without having to download them from some S3 bucket or something to make changes.

Unfortunatley Amazon doesn’t provide a UI to set up a “Custom Distribution” so you have to do a post request to a URL and send them some XML. It’s maybe not that hard but i really think they could provide us with some simple page where you just paste some XML and sent the request. But you have to do it yourself. The only thing i had issues with was to sign the request and get your “encrypted” secret.

I found some code on Stack Overflow (as usually) and just made some small modification to it for doing a Cloud Front setup request.

public static void InvalidateContent() {
    string httpDate = Helper.GetHttpDate();
 
    string AWSSecret = "YOUR SECRET";
    string AWSAccessKeyId = "YOUR ACCESS KEY";
 
    ASCIIEncoding encoding = new ASCIIEncoding();
    string postData = @"<DistributionConfig xmlns='http://cloudfront.amazonaws.com/doc/2010-11-01/'>
        <CustomOrigin>
            <DNSName>dist.alternativeto.net</DNSName>
            <HTTPPort>80</HTTPPort>
            <HTTPSPort>443</HTTPSPort>
            <OriginProtocolPolicy>match-viewer</OriginProtocolPolicy>
        </CustomOrigin>
        <CallerReference>" + httpDate + @"</CallerReference>
        <CNAME>static.alternativeto.net</CNAME>
        <Comment>My comments</Comment>
        <Enabled>true</Enabled>
        <Logging>
            <Bucket>mylogs.s3.amazonaws.com</Bucket>
            <Prefix>myprefix/</Prefix>
        </Logging>
    </DistributionConfig>";
    byte[] data = encoding.GetBytes(postData);
 
    // Prepare web request...
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://cloudfront.amazonaws.com/2010-11-01/distribution");
    webRequest.Method = "POST";
    webRequest.ContentType = "text/xml";
    webRequest.Headers.Add("x-amz-date", httpDate);
 
    Encoding ae = new UTF8Encoding();
    HMACSHA1 signature = new HMACSHA1(ae.GetBytes(AWSSecret.ToCharArray()));
 
    string b64 = Convert.ToBase64String(signature.ComputeHash(ae.GetBytes(webRequest.Headers["x-amz-date"].ToCharArray())));
 
    webRequest.Headers.Add(HttpRequestHeader.Authorization, "AWS" + " " + AWSAccessKeyId + ":" + b64);
 
    webRequest.ContentLength = data.Length;
 
    Stream newStream = webRequest.GetRequestStream();
    // Send the data.
    newStream.Write(data, 0, data.Length);
    newStream.Close();
}
 
/// <summary>
/// Gets a proper HTTP date
/// </summary>
public static string GetHttpDate() {
    // Setting the Culture will ensure we get a proper HTTP Date.
    string date = System.DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss ", System.Globalization.CultureInfo.InvariantCulture) + "GMT";
    return date;
}

 

Debug and fix the z-index bug in IE6 and IE7

Internet Explorer 6 and 7 has a really really annoying bug that makes it really hard to use z-index. I wont go into any specifics about exactly what is causing this and so on because others has already done that. I just want to tell you that i found this awesome jQuery script that inject z-index that IE6/IE7 can handle on the elements of a DOM tree. You can either just add this script and run it in production or you can use it to debug z-index problems in Internet Explorer.

Attach the Visual Studio debugger to Expression Blend for Windows Phone

I just watched Laurent Bugnion’s excellent talk about MVVM (Model-View-ViewModel pattern) from the MIX10 conference. In that talk he shows a cool trick when he attach the Visual Studio debugger to Expression Blend which lets you debug your design time code. It’s often really hard to figure out why your design time data doesn’t show up when using the MVVM pattern and this trick really helps you.

I had some problems to get it to work thou. First i thought it was some stupid limitation in Expression Blend for Windows Phone but after a while i realized that i had to choose “Manged (V4.0) code”. The default in my version of Visual Studio where “Manged (V2.0, v1.1, v1.0) code”. When i changed this everything worked perfectly. A more step-by-step description of how this works can be found here.

Find App ID so you can link to an Windows Phone 7 app on the Zune Marketplace

I wanted to link to a couple of of apps on the Zune marketplace today. Easier said then done. But i figured it out at last. Start with a link like this:

http://social.zune.net/redirect?type=phoneApp&id=APPID&source=Codepolice

Type is kind of obvious, ID is the one i had some problems with and source is just used for tracking and is optional.

How do i find the ID?

I spent 30 minutes on Google trying to figure this out and the only thing i found was this dude who had the same question. After a while i realized that Zune is of course using http to communicate with the world as everything else and since i have Fiddler installed i started it and browsed to an app in the Zune Marketplace and there i found it! Quick walkthough:

  1. If you do not have Fiddler just download it from their website.
  2. Start Fiddler and then browse to an application in the Marketplace with your Zune Software. You should see stuff happening in Fiddler.
  3. In the URL column look for a a URL looking something like this: http://catalog.zune.net/v3.2/en-GB/apps/981750c8-24cc-df11-9eae-00237de2db9e/?version=latest&clientType=WinMobile%207.0&store=Zest
  4. The long string (it’s a GUID) you see in green above is the ID you looking for.
  5. Just copy the ID into the URL and you have a fine link.

Final result: http://social.zune.net/redirect?type=phoneApp&id=981750c8-24cc-df11-9eae-00237de2db9e&source=Codepolice

Let’s hope Microsoft make this a bit easier soon.

Having problem adding a simple image to a Windows Phone 7 app?

I’m not the type of person who first watch 10 videos and read lots of documentation before i jump into some new environment. Therefore it’s kind of easy to get stuck on trivial and stupid problems like this one.

I just wanted to add an image and show it in the “ApplicationBar” but it simply would not work. At last i figured out that i had to change the image properties to.

Build Action -> Content
Copy to Output Directory -> Copy Always