December 28, 2012

The underlying type of CLR enumeration type does not match the underlying type of EDM enumeration type

Entity Framework has supported the enumeration type since its version 5. I followed tutorials at Enum Support - EF Designer and Entity Framework 5 + Enumerations => What’s not to love? to add the enum type in my model, however, I got 'The underlying type of CLR enumeration type does not match the underlying type of EDM enumeration type' in Test Explorer after I ran one of my unit tests against a SQL Server 2008 database.
The column in my database table is of type 'tinyint', which will map to 'byte' in .NET. And here's what my enum type looks like.
    public enum ForgotPasswordStatus
    {
        Pending = 0,
        Verified = 1
    }

Checking another article at USING EXISITING ENUM TYPES IN ENTITY FRAMEWORK 5, I found the reason I got the error was because I did not explicitly define the underlying type of my enum ForgotPasswordStatus. After adding the underlying type to my enum as follows, my test passes now.
    public enum ForgotPasswordStatus : byte
    {
        Pending = 0,
        Verified = 1
    }

December 25, 2012

Avoid creating your own SMTP settings

The <mailSettings> element has been around for years since the .NET Framework 2.0, but I still found people tend to create their own SMTP settings in the <appSettings> element like below.

<add key="SmtpServer" value="smtp.pete.tw"/>
<add key="SmtpUsername" value="pete"/>
<add key="SmtpPassword" value="F4g%j&k9"/>
<add key="SmtpPort" value="25"/>
<add key="SmtpEnableSSL" value="False"/>

Well, I know some are legacy projects you don't even want to touch, jsut like the famous phrase says - if it ain't broken, don't fix it. But for new projects, we should definitely use <mailSettings> for writing neat code and not messing up the <appSettings> element. Refer to http://msdn.microsoft.com/en-us/library/w355a94k.aspx and have your own configuration as below, the SmtpClient class in your code will read the <mailSettings> element automatically from your App.config/Web.config.

<system.net>
  <mailSettings>
    <smtp deliveryMethod="Network" from="Pete&lt;admin@pete.tw&gt;">
      <network defaultCredentials="true" host="smtp.pete.tw" port="25" enableSsl="false" userName="pete" password="F4g%j&k9" />
    </smtp>
  </mailSettings>
</system.net>

December 24, 2012

A project which specifies SQL Server 2012 as the target platform cannot be published to SQL Server 2008

Executing the Schema Compare in Visual Studio 2012, I get the error message "A project which specifies SQL Server 2012 as the target platform cannot be published to SQL Server 2008."


This error occurs because in Visual Studio 2012 the target platform of the database project is by default set to SQL Server 2012 and your database to be compared does not match the setting. If your target database is SQL Server 2008 like me for example, you can follow the below steps to change the target platform.
  1. Right-click on the project name in Solution Explorer and click Properties.
  2. Click the Project Settings tab.
  3. Change the target platform from SQL Server 2012 to SQL Server 2008.
  4. Save the project and execute the Schema Compare function again.

December 23, 2012

Turn off auto-restart after windows update

It's sometimes annoying when I come to the office next morning and find my development environment (it's a virtual machine) restarted automatically without my permission.I install Windows 7 Ultimate as my operating system and by default it will restart the system automatically after the windows update has been done (although you may argue that I should've changed the default settings when I installed the OS at the beginning). But as a developer, you won't like being interrupted by this when you are in the flow. Here's how we can disable the auto-restart feature.
  1. Go to Run.., input gpedit.msc and click OK.
  2. Expand Computer Configuration-> Administrative Templates-> Windows Components-> Windows Update and you will see a setting called No auto-restart with logged on users for scheduled automatic updates installations in the right pane.
  3. Right-click on this setting and edit it.
  4. Select Enabled and click OK to take effect.
  5. (Optional) Repeat the above steps on the server hosting your virtual machine.

December 19, 2012

Saving changes is not permitted

When you use SQL Server 2008 and try to add a new column in the existing table, you get the following alert and cannot proceed with the modification on the table schema.


This happens when you install a brand-new SQL Server 2008 on your machine. The solution to the above is to disable "Prevent saving changes that require table re-creation" thru Tools-> Options-> Designers-> Table and Database Designers.


December 9, 2012

遠端重啟DrayTek Vigor2950G

公司的Router是用這一台,不知怎麼的它的網頁管理介面每隔一段時間就會掛掉,之前只能透過手動將Router重開機才會回復正常。不過因為一些因素Router是擺在別人的機房,每次就得麻煩別人幫忙重開,好在它提供了telnet及command line的功能,只要透過telnet [Router IP Address]後,驗証完密碼後再執行sys reboot指令即可將Router重開。