Windows DNS fails with SPF/TXT too long

3 Comments

I run my own DNS for some of my domains. My primary DNS is the built-in DNS service in Windows 2003 SP1 and as backup/secondary DNS I’m using a free service from Twisted4Life. I’ve been using SPF for a couple of years and it has been working fine.
(SPF – Sender Policy Framework – is way to prevent spam by entering into your DNS what SMTP servers are allowed to send email for your domain. Some email systems such as Hotmail rely in part on SPF when deciding if your email should be placed in the recipients Inbox or Junk mail folder.)

My ISP has been recommending me to use a new SMTP server when sending out email from one of my email lists. So two days ago I added a few new SMTP servers to my SPF record in my DNS (by updating the DNS file in my \Windows\System32\DNS directory and then doing Reload from the DNS console, dnsmgmt.exe) A quick look and everything seemed just fine.

Normally when sending my email list, which contains a bit over 20k recipients, it takes about 10-20 minutes to actually send the batch and then during the next 10 minutes I get about 4-500 error emails telling me stuff like “user is over quota”, “no such user” (I use these to clean my email list after each batch).
This time I only got about 15 error messages per hour and it took 36 hours before all had arrived in my inbox!
During this 36 hour period I called my ISP and told them there has to be something wrong with the new SMTP server that they had recommended I switch to. I also did send a test batch using the old SMTP server and it was lightning fast as always.

Today I noticed that I had not recieved any emails from a colleague who is using another email system than me. He told me that he sent me several emails yesterday and this morning and had not recieved any error messages. I told him to call his ISP because my email was working fine, I had emailed back and forth with several people and had no problem.

Then this evening it struck me – I had completely forgot that I made changes to my DNS records. Could I have put something wrong in my SPF records? But why would that effect my incoming email?

First I just did a nslookup using centralops.net online nslookup. This tool reported “Name server failed” for my domains! I quickly tried another online nslookup tool from network-tools.com and this tools reported no errors, it worked fine.

I went in to my server and opened the DNS console. And there, on the line showing the TXT record I use for my SPF string there was a blank space about ten characters into the string, in the middle of one of my SMTP server entries. At the end of the string there was some kind of special character, represented by a “square box”. I then looked at the DNS data file at \Windows\system32\DNS but that still looked exactly like it should, without any blank spaces or special characters. Strange…

I then updated the data file from the DNS console (instead of the other way around that I usually do).
When I checked the DNS data file, my TXT record was split into several lines, with line breaks between them, each line starting and ending with a quotation mark. However some characters were missing at the line breaks so I reverted back to the original errornous case, ie where the DNS data file looks fine but in the DNS console there is a blank space and a special character.

Then I went to kitterman.com’s SPF validation tool to validate my SPF string. The actual string validated fine. But then, using the same tool, I asked it to validate my domain using a DNS lookup it failed.

Finally, I deleted a few old SMTP servers from my SPF string in the DNS data files and did Reload on the DNS console. Ran my checks again and everything worked fine. And as I’m typing this blog post emails up to 48 hours old have started to enter my inbox.

My conclusion is that using a string that is too long (I have not done any extensive search on this problem, so I don’t know how long a string is allowed to be) in a TXT record corrupts the string. This is obviously a bug Windows DNS server.
But the thing that is strange to me is that to some DNS clients, the answer my DNS server sent them was ok and to some unacceptable. I also don’t understand why the SMTP servers reacted this way – no delivery I could understand, but extremely slow delivery?

Well, I’m a novice at both DNS and SMTP, so to others this may be crystal clear – please enlighten me!

SQL Server 2005 SP2 killed my web sites

3 Comments

A few days ago I was visiting my web server (running Windows 2003). Windows Update prompted me to install the SQL Server 2005 Service Pack 2 update so I went ahead and clicked ok to do that.

Yesterday I was surfing thru my web sites and realized that some of my web sites running on that server did not work as they were supposed to do, ie they only gave an error screen 🙁

It turns out the update had stopped my SQLServer service and some of my web sites had been down or partially down for several days.

I know this is my own fault, that I should have checked the server after running a major update, but I was so sure that anything coming thru Windows Update would not stop anything critical on a server. Well, lesson learned… (I hope)

Unable to convert MySQL date/time value to System.DateTime

17 Comments

After switching from MySQL ODBC driver to the .NET connector I have been getting this error: Unable to convert MySQL date/time value to System.DateTime.

This is when a DATETIME or DATE field contains an invalid value. It turns out that 0000-00-00 which I have used as default value in a DATE column is considered an invalid date. Instead NULL should be used when date/time is not set.

The one solution I found is to add Allow Zero Datetime=True to the connection string, this allows for 0000-00-00 00:00:00 in a DATETIME column. Just add it at the end of your connection string so it looks something like this:
<add key="connectionString" value="Database=your_db;Data Source=localhost;User Id=root;Password=password;Allow Zero Datetime=True;"/>

This however did not seem to work 100% for my code.
In VB.NET I was using this piece of code to check if the valid_until field (of type DATE) is set or not:
If ("" & myDataReader("valid_until")) = "" Then ...

I was concatenating to an empty string istead of using .ToString() because this (if I remember it correctly) would catch both NULL and 0000-00-00 values (both would evaluate to empty string).
Now instead I got this error message: Conversion from type ‘MySqlDateTime’ to type ‘String’ is not valid.

With ODBC, 0000-00-00 used to evaluate to empty string, but using the .NET connector with the connection string work around it returns the actual value, so I have to check for the zeroes instead. So, the solution to my problem is of course to use the proper .ToString function and check for both “0000-00-00” and empty string returned for null value (or even better – use the proper IsDBNull function).

Another way besides using the connection string workaround is of course to fix the data.

  • First check the data definitions in your databases to make sure it does not default to 0000-00-00 (for data type DATE) or 0000-00-00 00:00:00 (for data type DATETIME). I’m still running MySQL server version 4 but I think that on version 5, using 0000-00-00 as default value is no longer valid.
  • Then update the data. An SQL statement to update a column of type DATE would typically look like this for a column named valid_until:
    UPDATE your_table SET valid_until=null WHERE valid_until LIKE '0000-00-00';

Vista and World Community Grid

3 Comments

I haven’t been able to get the World Community Grid (WCG) client (United Devices UD.EXE) to run well on my Vista machine. It has been running for awhile then giving me messages like “Unable to process Task data. Backing-off.”

I have Googled but not found a solution. Then today I went directly to the World Community Grid forum, it seems the forum is not indexed by Google for some strange reason.
Anyway I after reading the forum it seems to be a security issue when running on Vista.

Two solutions that seem to be working well:

1) Change security settings for C:\Program Files\World Community Grid (or wherever you installed) so that the group USERS have Full Control.

2) This I have not tried myself but is confirmed by many forum postings: Try to install outside C:\Program Files, e.g. C:\WCG, or even on a different partition than your
system, i.e. not on C:

I also tried running the WCG client (UD.EXE) using the Run as administrator option in Vista (right click the program icon and select Run as administrator). It seems to be working even if I for some reason at first got the logon screen in WCG client. This will not work if you have WCG run at startup.

You would think this problem/solution is something that should be
1) Hilited on the WCG homepage (at least the download section)
2) Fixed in the client or install program

By the way – If you’re not already running WCG, why not start today. Let your computer help solve world problems while you don’t use it yourself, e.g. when you’re on your coffee break.
I recieved this email the other day, this is truly great stuff!

World Community Grid is pleased to announce that the Help Defeat Cancer (HDC) project is finished. The last work units have been sent out and when the final results are returned, the project will come to an end. This project, which launched on July 20, 2006, will have run for just over 9 months by the time the last results are returned. During this time 88,000 members will have donated 2,900 years of computer time on 138,000 different computers. This is a significant contribution to cancer research.

.NET and MySQL in Five Easy Steps

No Comments

I’ve been using the MySQL ODBC driver for a long time now in my ASP.NET projects (as posted about here). But today when I was about to start a new project on my new Vista machine I thought I’d check if anything new had emerged the last years when it comes to MySQL drivers for .NET – and not too surprisingly there is now (probably been there for a loooong time) an ADO.NET driver called ADO.NET Driver for MySQL Connector/NET.

So this post is on how to get it going, it’s very straight forward.
This is tried on Vista with Visual Studio 2005 SP1 and the Visual Studio 2005 Service Pack 1 Update for Windows Vista using the ADO.NET Driver for MySQL (Connector/NET) version 5.0.6.

1) Download and install (using the included installer) the ADO.NET Driver for MySQL Connector/NET.

2) Create or open a project in Visual Studio 2005. I’m using a VB.NET console project in my example.

3) Go to Project + Add Reference…
On the .NET tab find and hilite MySQL.Data and then click Ok.
(It seems this step can be skipped sometimes…)
[Update: In an ASP.NET project go to Website + Add Reference]

4) Go to Project + YourProject Properties… + References Tab
Under Imported Namespaces check MySql.Data.MySqlClient and MySql.Data.Types and save.
[Update: In an ASP.NET project open web.config and add as namespace under configuration – system.web – pages – namespaces]

5) Write your code and run it. Here is an example to get you started:

Dim myConnectionString As String = "Database=TestDB;Data Source=localhost;User Id=TestID;Password=TestPwd"
Dim myConnection As New MySqlConnection(myConnectionString)
Dim myCommand As New MySqlCommand("SELECT * FROM testtable", myConnection)
Dim myDataReader As MySqlDataReader
myConnection.Open()
myDataReader = myCommand.ExecuteReader
While myDataReader.Read
Console.WriteLine(myDataReader("testcolumn"))
End While
myDataReader.Close()
myConnection.Close()

More examples can be found in the manual from MySQL.

Note: If your accessing your MySQL server on another machine, i.e. not as localhost, you need to make sure the firewall on the server allows access on TCP port 3306. If the server is using Windows firewall just simply go into Control Panel – Windows Firewall – Exceptions Tab click Add Port. (Just make sure you remember to disable the port again after you are done testing!)