Quantcast
Channel: JPHellemons
Viewing all 132 articles
Browse latest View live

External hard drive is not available

$
0
0

imageMy external hard drive is unavailable in Windows when I tried to open it in explorer (my computer) I was really annoyed by it, because it is my primary backup disk. I have found HD Tune free which is a great tool to scan your (external) drive for errors. The “quick scan” came out clean. The complete scan took a while but also was 100% green.

image

But still no access to the drive. On a dutch computer magazine website I found this small (also free) util called EaseUS data recovery. It can recover 2gb for free, but it can always scan your full drive to see if it can be of any help and is worth the buy. That tool also found all files:

image

But still no access to the drive. After some searching the interwebz I found an article which suggested to check the disk management of Windows if that would list the drive and if it would list the partitions.

image

And there is the error! The external drive is in RAW filesystem!? I have never ever heard before of a raw filesystem. I expected NTFS (because it can handle *.iso of over 4gb)

So I have found this article How to fix external drive suddenly became raw. That article suggests that you use Parted Magic which is no longer a free download, but still is available on majorgeeks.

You can also download testdisk for windows so that you do not have to burn an linux iso and reboot your PC. http://www.cgsecurity.org/wiki/TestDisk_Step_By_Step

image

There are a few guides online for the testdisk tool. I did not had to fix the mbr but I did write the partition table for the external harddrive. All that was left was just running checkdisk:

chkdsk F: /F
This solved it for me.

I will use the unplug usb drive build in windows feature everytime I use my external harddrive from now on.

Please read this if you do not know how to safely remove the usb drive in windows.

Good luck!


Missing Asp.Net webAdmin configuration option in Visual Studio 2013

$
0
0

If you are still working with WebForms and the FormsAuthentication in visual studio 2013, you are probably missing the option `Asp.Net Configuration` which fires a tool to configure users and groups for your asp.net webapplication.

Sorry for the dutch screenshot by the way. But this is the tool that I am referring to.

image

I have found this post about manually starting IIS Express to manage it and I had some problems with it, so that is the reason that I am blogging about it. To help others, but also as a reference for myself if I have this issue again.

    1. Open Command Prompt (Windows key + X, or Windows key + R, cmd <enter>)
    2. Navigate to the IIS Express folder (cd C:\Program Files\IIS Express <enter>)
    3. Copy paste this:
      iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/webadmin" /port:12345 /clr:4.0 /ntlm
    4. Open your browser and navigate to: http://localhost:12345/webadmin/default.aspx?applicationPhysicalPath=C:\Path\to\your\webformcode\&applicationUrl=/ (I had to login with my windows account) Do not forget to change the path to your code!

image

You can close IIS Express in the console with `Q` if you are done. I hope that this option will be put back in Visual Studio 2013 update 1 or something for all those webform developers.

Good luck!

    After 4 months working with the Nokia Lumia 920 and Windows Phone 8

    $
    0
    0

    I have bought the Nokia Lumia 920 about 4 months ago and wanted to blog a review. Please note that this is written in the end of November 2013 and that things might have changed since this has been written. Perhaps there are OS updates released, or Nokia updates or app releases/updates. I got the Lumia with the Portico update but I received the upgrade to gdr2 (Microsoft update) and amber (Nokia update) rather quick after buying the device. I have blogged before aobut my experience about the upgrade from gdr1 to gdr2. Which was painless. I have enrolled in the developer program of Microsoft (for about 18 euro’s) and have enrolled in the GDR3 preview program. Microsoft bought Nokia during the past 4 months and they have unlinked the Nokia update (Bittersweet shimmer, now called Black update) and the GDR3 update from Microsoft. So I have the GDR3 preview at the moment and I have to wait for the GDR3 final. Nokia will release the black update after Microsoft finalizes gdr3. There are also resources online which claim that there will be an enterprise update in Q1 of 2014 for Windows Phone 8. An other post is 4 months old and there is a timespan of q1 or q2 for the enterprise update. On the previous link (official Microsoft site) is also an announcement about the increased lifecycle support for Windows Phone. They have increased it from a year and a half to three years! Eat your heart out Android! You can have a telephone running windows phone 8 for as little as 140 euro’s. (Nokia Lumia 520) That is an awesome budget phone with a great OS!

    pros

    • no lag! fluent user interface
    • all mandatory apps are available
    • unified UI
    • good lifecycle support (Operating System updates)
    • Nokia adds nice things to the OS
    • growing market share (especially in Europe)
    • awesome camera (Lumia 1020 even has 41 megapixel!)
    • decent hardware (Nokia’s are stronger than Thors hammer)
    • auto Skydrive upload (had Dropbox on my Android HTC Desire C which was also nice)
    • tiles! you just have to experience them
    • good Bluetooth sync with (Ford) car
    • Nokia Drive+ included (for non Nokia phones it’s about 35 dollar/euro)
    • a lot of Nokia apps (for camera’s)
    • Facebook app is more responsive on windows phone than on my HTC Desire running Android 4.x
    • same for Whatsapp
    • no app required for barcode scanning (build in OS)
    • no app required to check who is singing this song (build in OS)
    • you can open Microsoft Office documents
    • build in PDF support
    • screenshots are easy

    cons (Microsoft and/or Nokia can improve this)

    Conclusion

    My next phone will definitely be a (Nokia) Windows Phone! Looking forward to the new 9xx phones. Because the 1020, 1520 are both too big. I even pushed my first windows phone app to the appstore. It is a small and simple flashlight (zaklamp) It is free, so check it out!

    As you can see, the most caveats are about missing Dutch (minor) applications. This is just a matter of time. The rest are just missing features in apps. There are no or almost no downsides to the mobile operating system that windows phone 8 (gdr3) is. Please let me know if you agree or disagree. Looking forward to your point of view!

    Visual Studio designer generation failed HRESULT E_FAIL call to COM

    $
    0
    0

    but COM was not at home, so COM could not answer ;)we_not_alone_02

    This was my error (it was actually a warning according to Visual Studio 2013):

    Warning 13 Generation of the designer file for MagazineDetails.aspx failed: Error HRESULT E_FAIL has been returned from a call to a COM component. C:\www\myproject\MagazineDetails.aspx

    It is the same error as the following people have/had:

    I am not alone, so I decided to blog about it. My configuration contains a Windows 8.1 x64 install with all the latest updates and have Visual Studio 2013 (version 12.0.21005.1) and I had this issue with just one aspx file.

    The error was not even visible at first. I had to lower the warning level (it was 4, and error was visible at 3)

    project-settings

    The thing is that this invisible error broke my intellisense and when I added controls like literals, buttons, labels etc. to the aspx. The “codebehind” (aspx.cs) did not recognize them. It was frustrating! And this was only an issue with one or two aspx files. (out of 30 or something)

    On stackoverflow there were three rather nice suggestions:

    • (re-)convert to web application the project
    • switch to the designer and back to re-generate
    • restart visual studio

    Unfortunately, none of the above fixed my problem. I found an other suggestion and cannot find the source, so I am sorry that I can not give credits to the person who pointed me in the right direction. But the solution is to add a classname to the page directive. Somehow it caused the IDE to recognize all the controls in the code behind and re-enabled the intellisense in the code behind.

    <%@ Page Title="Magazine details" Language="C#" MasterPageFile="~/nl.Master" AutoEventWireup="true" CodeBehind="MagazineDetails.aspx.cs" Inherits="NikkiLissoni.MagazineDetails" ClassName="NikkiLissoni.MagazineDetails" %>

    I hope this will help out other developers and might save them an hour or two searching for a solution for this strange behaviour.

    Good luck!

    kick it on DotNetKicks.comShout it

    SQL Azure connection timeout expired

    $
    0
    0

    Since we moved from an on premises SQL Server to SQL Azure we experienced a lot of timeouts. This is the exact errormessage:


    Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=3; handshake=29995;

    After searching the web for a while it appeared that it is recommended to use the Microsoft Enterprise Library. Version 6 was released last April. So there are not so much code samples at the moment. But there is a free e-book! Developer's Guide to Microsoft Enterprise Library, 2nd Edition. You can download it for free from Microsoft's website or order a paperback from amazon.


    I installed two nuget packages for the enterprise library.2014-01-03 16_35_03-Shop - Manage NuGet Packages

    My data access class required these two additions to the usings:

    using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
    using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling;

    And my function which returns a simple datatable looks like this now:

    public static DataTable GetDatatable(SqlCommand com)
    {
        DataTable dt = new DataTable();
    
        RetryStrategy retryStrategy = new Incremental("fixed", 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
        RetryPolicy retryPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy);
        retryPolicy.Retrying += new EventHandler<RetryingEventArgs>(retryPolicy_Retrying);
    
        List<RetryStrategy> retryStrategies = new List<RetryStrategy> { retryStrategy };
    
        var manager = new RetryManager(retryStrategies, "fixed"); // this name must match the name of the incremental
    
        try
        {
            RetryManager.SetDefault(manager); // you have to set the default
        }
        catch { } // but you cannot check if it is already set, that's why I used a try, catch
    
        try
        {
            retryPolicy.ExecuteAction(() =>
            {
                using (SqlConnection con = new SqlConnection(GetConStr()))
                {
                    com.Connection = con;
                    SqlDataAdapter da = new SqlDataAdapter(com);
    
                    con.OpenWithRetry();
                    da.Fill(dt);
                }
            });
        }
        catch (Exception e)
        {
            WriteDbError(e, com);
        }
        return dt;
    }
    

    I know that you can configure the enterprise library to use settings from the web.config. I decided to use hardcoded “variables” because they do not change (much). Please let me know if you have more improvements for the code above. I have a simple GetConStr() method which just returns the connection string from the web.config file.

    So this code will solve about 99% of your azure timeouts!

    Good luck! Let me know your opinion in the comments!

    ps. Happy new year!

    Shout itkick it on DotNetKicks.com

    Develop a Windows Phone 7 application on Windows 8.1

    $
    0
    0

    As mentioned in the post “After 4 months working with the Nokia Lumia 920 and Windows Phone 8” I build a really simple flashlight application for Windows Phone 8. According to AdDuplex (27th of December 2013) there is still a 21.7% of all Windows Phone users which run Windows Phone 7.x So I decided to make this tiny flashlight application also available for those 21.7%. It is a small app so it should be rather easy, don’t you think? Well to summarize, it is not! Perhaps just because my CPU does not support SLAT (Second Level Address Translation) so I have to debug on a Windows Phone device (which runs version 7 or 8)

    clip_image004

    When you run Windows 8, you can not develop a windows phone 7.x application and test it on a device. You need Windows 7, Visual studio 2010 or 2012, Zune and the WP SDK. I have tried everything to get it to work on Windows 8.1 x64 as you can read on this StackOverflow topic “Register Windows Phone 7 as developer phone” I have added firewall rules, ran all windows updates, have the latest version of SDK’s, visual studio updates etc. Even when you have registered a Windows Phone 7 as developer phone, you get this error 0x80070103

    image

    In order to be able to develop a Windows Phone 7 application on a Windows 8.1 machine, you need SLAT (to run the wp emulator) or.... a virtual machine! Hyper-V is build in by default in Windows 8 but also no valid option because it also requires SLAT support. So I installed Vmware Player/workstation (Oracle’s Virtualbox is also an option) and installed Windows 7 on it with Zune 4.8 and the Windows Phone 7.1 SDK but first the Visual Studio 2010 Express for Windows Phone.

    image

    I personally ran into an other issue. I had the vm on an external usb harddrive. And somehow there was a read/write error so my vm became corrupted. I had to ‘upgrade’ my vmware player to vmware workstation to run vmware-vdiskmanager. The solution was online in the knowledge base of vmware to fix the corrupted vmdk file.

    A small side note about Visual Studio 2010 express for Windows phone by the way is that you cannot install nuget for it! So please keep in mind that you might want to use a better/larger version of Visual Studio in your VM.

    Good luck developing Windows Phone 7 applications on your Windows 8.1 host machine!

    Working with the Dymo label sdk on Windows 2012 server

    $
    0
    0

    Dymo has some great label printing hardware and has a nice .Net SDK. It seems that they are moving away from the .Net SDK and more towards the JavaScript SDK. In my situation I wanted to host a small Rest service on a Windows 2012 server so that I can make an Ajax call with jQuery to it to print a label from my web application. So it is a kind of printing proxy with REST. We had previously only Internet explorer support in our web application, so using the Active X component was easy for us. Though it required a client installation and the client to configure the network shared printer.

    The strange thing is that this code looks good at first sight. Also if you compare it with the Dymo label code. It even works great on my machine, but when I put it live on our production server it failed. No exception or whatsoever, but it simply said that there is no label writer.

    StringBuilder sb = new StringBuilder
    var label = DYMO.Label.Framework.Label.Open(System.Web.HttpContext.Current.Server.MapPath(@"~/Content/thelabel.label")); // mvc webapplication
    label.SetObjectText("Address", sb.ToString());
    label.Print(ConfigurationManager.AppSettings.Get("printername"));
    // printername = \\pcname\dymo

    Even when I list the label printer, it does not show up in the list. Printing with the default label printing software from dymo (version 8.x) works great on my machine and the server, but not by code.

    StringBuilder sbPrinters = new StringBuilder();
    DYMO.Label.Framework.Printers p = new DYMO.Label.Framework.Printers();
    foreach(var printer in p.ToList())
    {
        sbPrinters.AppendLine(printer.Name);
        sbPrinters.AppendLine(printer.ModelName);
        sbPrinters.AppendLine(printer.IsConnected.ToString());
        sbPrinters.AppendLine(printer.IsLocal.ToString());
        sbPrinters.AppendLine("-==========-");
    }
    return sbPrinters.ToString(); // empty...

    I have tried an Asp.Net web application 4.5 with WebApi on Windows 2012 and a 4.0 Webforms application on Windows 2003. Both did not work. So what is wrong? I used the build in Visual Studio development server and on both windows servers (2003 and 2012) I used IIS. So that might be the problem. I have heard about Katana and OWIN and started a small test project with this guide. Somehow it works when you are not using IIS! I also tried Asp.Net impersonation in the web.config. Maybe running in full trust works, but I prefer a tiny Windows Service with Owin. So go check out the project page of Katana on codeplex or simply pull down this Nuget package of Microsoft Owin. This Channel9 video of 43 minutes is also a great online source to learn more about the Katana project, OWIN for Asp.Net.

    Good luck with the Dymo .Net SDK!

    External hard drive is not available

    $
    0
    0

    imageMy external hard drive is unavailable in Windows when I tried to open it in explorer (my computer) I was really annoyed by it, because it is my primary backup disk. I have found HD Tune free which is a great tool to scan your (external) drive for errors. The “quick scan” came out clean. The complete scan took a while but also was 100% green.

    image

    But still no access to the drive. On a dutch computer magazine website I found this small (also free) util called EaseUS data recovery. It can recover 2gb for free, but it can always scan your full drive to see if it can be of any help and is worth the buy. That tool also found all files:

    image

    But still no access to the drive. After some searching the interwebz I found an article which suggested to check the disk management of Windows if that would list the drive and if it would list the partitions.

    image

    And there is the error! The external drive is in RAW filesystem!? I have never ever heard before of a raw filesystem. I expected NTFS (because it can handle *.iso of over 4gb)

    So I have found this article How to fix external drive suddenly became raw. That article suggests that you use Parted Magic which is no longer a free download, but still is available on majorgeeks.

    You can also download testdisk for windows so that you do not have to burn an linux iso and reboot your PC. http://www.cgsecurity.org/wiki/TestDisk_Step_By_Step

    image

    There are a few guides online for the testdisk tool. I did not had to fix the mbr but I did write the partition table for the external harddrive. All that was left was just running checkdisk:

    chkdsk F: /F
    This solved it for me.

    I will use the unplug usb drive build in windows feature everytime I use my external harddrive from now on.

    Please read this if you do not know how to safely remove the usb drive in windows.

    Good luck!


    Missing Asp.Net webAdmin configuration option in Visual Studio 2013

    $
    0
    0

    If you are still working with WebForms and the FormsAuthentication in visual studio 2013, you are probably missing the option `Asp.Net Configuration` which fires a tool to configure users and groups for your asp.net webapplication.

    Sorry for the dutch screenshot by the way. But this is the tool that I am referring to.

    image

    I have found this post about manually starting IIS Express to manage it and I had some problems with it, so that is the reason that I am blogging about it. To help others, but also as a reference for myself if I have this issue again.

      1. Open Command Prompt (Windows key + X, or Windows key + R, cmd <enter>)
      2. Navigate to the IIS Express folder (cd C:\Program Files\IIS Express <enter>)
      3. Copy paste this:
        iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/webadmin" /port:12345 /clr:4.0 /ntlm
      4. Open your browser and navigate to: http://localhost:12345/webadmin/default.aspx?applicationPhysicalPath=C:\Path\to\your\webformcode\&applicationUrl=/ (I had to login with my windows account) Do not forget to change the path to your code!

    image

    You can close IIS Express in the console with `Q` if you are done. I hope that this option will be put back in Visual Studio 2013 update 1 or something for all those webform developers.

    Good luck!

      After 4 months working with the Nokia Lumia 920 and Windows Phone 8

      $
      0
      0

      I have bought the Nokia Lumia 920 about 4 months ago and wanted to blog a review. Please note that this is written in the end of November 2013 and that things might have changed since this has been written. Perhaps there are OS updates released, or Nokia updates or app releases/updates. I got the Lumia with the Portico update but I received the upgrade to gdr2 (Microsoft update) and amber (Nokia update) rather quick after buying the device. I have blogged before aobut my experience about the upgrade from gdr1 to gdr2. Which was painless. I have enrolled in the developer program of Microsoft (for about 18 euro’s) and have enrolled in the GDR3 preview program. Microsoft bought Nokia during the past 4 months and they have unlinked the Nokia update (Bittersweet shimmer, now called Black update) and the GDR3 update from Microsoft. So I have the GDR3 preview at the moment and I have to wait for the GDR3 final. Nokia will release the black update after Microsoft finalizes gdr3. There are also resources online which claim that there will be an enterprise update in Q1 of 2014 for Windows Phone 8. An other post is 4 months old and there is a timespan of q1 or q2 for the enterprise update. On the previous link (official Microsoft site) is also an announcement about the increased lifecycle support for Windows Phone. They have increased it from a year and a half to three years! Eat your heart out Android! You can have a telephone running windows phone 8 for as little as 140 euro’s. (Nokia Lumia 520) That is an awesome budget phone with a great OS!

      pros

      • no lag! fluent user interface
      • all mandatory apps are available
      • unified UI
      • good lifecycle support (Operating System updates)
      • Nokia adds nice things to the OS
      • growing market share (especially in Europe)
      • awesome camera (Lumia 1020 even has 41 megapixel!)
      • decent hardware (Nokia’s are stronger than Thors hammer)
      • auto Skydrive upload (had Dropbox on my Android HTC Desire C which was also nice)
      • tiles! you just have to experience them
      • good Bluetooth sync with (Ford) car
      • Nokia Drive+ included (for non Nokia phones it’s about 35 dollar/euro)
      • a lot of Nokia apps (for camera’s)
      • Facebook app is more responsive on windows phone than on my HTC Desire running Android 4.x
      • same for Whatsapp
      • no app required for barcode scanning (build in OS)
      • no app required to check who is singing this song (build in OS)
      • you can open Microsoft Office documents
      • build in PDF support
      • screenshots are easy

      cons

      Conclusion

      My next phone will definitely be a (Nokia) Windows Phone! Looking forward to the new 9xx phones. Because the 1020, 1520 are both too big. I even pushed my first windows phone app to the appstore. It is a small and simple flashlight (zaklamp) It is free, so check it out!

      As you can see, the most caveats are about missing Dutch (minor) applications. This is just a matter of time. The rest are just missing features in apps. There are no or almost no downsides to the mobile operating system that windows phone 8 (gdr3) is. Please let me know if you agree or disagree. Looking forward to your point of view!

      Visual Studio designer generation failed HRESULT E_FAIL call to COM

      $
      0
      0

      but COM was not at home, so COM could not answer ;)we_not_alone_02

      This was my error (it was actually a warning according to Visual Studio 2013):

      Warning 13 Generation of the designer file for MagazineDetails.aspx failed: Error HRESULT E_FAIL has been returned from a call to a COM component. C:\www\myproject\MagazineDetails.aspx

      It is the same error as the following people have/had:

      I am not alone, so I decided to blog about it. My configuration contains a Windows 8.1 x64 install with all the latest updates and have Visual Studio 2013 (version 12.0.21005.1) and I had this issue with just one aspx file.

      The error was not even visible at first. I had to lower the warning level (it was 4, and error was visible at 3)

      project-settings

      The thing is that this invisible error broke my intellisense and when I added controls like literals, buttons, labels etc. to the aspx. The “codebehind” (aspx.cs) did not recognize them. It was frustrating! And this was only an issue with one or two aspx files. (out of 30 or something)

      On stackoverflow there were three rather nice suggestions:

      • (re-)convert to web application the project
      • switch to the designer and back to re-generate
      • restart visual studio

      Unfortunately, none of the above fixed my problem. I found an other suggestion and cannot find the source, so I am sorry that I can not give credits to the person who pointed me in the right direction. But the solution is to add a classname to the page directive. Somehow it caused the IDE to recognize all the controls in the code behind and re-enabled the intellisense in the code behind.

      <%@ Page Title="Magazine details" Language="C#" MasterPageFile="~/nl.Master" AutoEventWireup="true" CodeBehind="MagazineDetails.aspx.cs" Inherits="NikkiLissoni.MagazineDetails" ClassName="NikkiLissoni.MagazineDetails" %>

      I hope this will help out other developers and might save them an hour or two searching for a solution for this strange behaviour.

      Good luck!

      kick it on DotNetKicks.comShout it

      SQL Azure connection timeout expired

      $
      0
      0

      Since we moved from an on premises SQL Server to SQL Azure we experienced a lot of timeouts. This is the exact errormessage:


      Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=3; handshake=29995;

      After searching the web for a while it appeared that it is recommended to use the Microsoft Enterprise Library. Version 6 was released last April. So there are not so much code samples at the moment. But there is a free e-book! Developer's Guide to Microsoft Enterprise Library, 2nd Edition. You can download it for free from Microsoft's website or order a paperback from amazon.


      I installed two nuget packages for the enterprise library.2014-01-03 16_35_03-Shop - Manage NuGet Packages

      My data access class required these two additions to the usings:

      using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
      using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling;

      And my function which returns a simple datatable looks like this now:

      public static DataTable GetDatatable(SqlCommand com)
      {
          DataTable dt = new DataTable();
      
          RetryStrategy retryStrategy = new Incremental("fixed", 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
          RetryPolicy retryPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy);
          retryPolicy.Retrying += new EventHandler<RetryingEventArgs>(retryPolicy_Retrying);
      
          List<RetryStrategy> retryStrategies = new List<RetryStrategy> { retryStrategy };
      
          var manager = new RetryManager(retryStrategies, "fixed"); // this name must match the name of the incremental
      
          try
          {
              RetryManager.SetDefault(manager); // you have to set the default
          }
          catch { } // but you cannot check if it is already set, that's why I used a try, catch
      
          try
          {
              retryPolicy.ExecuteAction(() =>
              {
                  using (SqlConnection con = new SqlConnection(GetConStr()))
                  {
                      com.Connection = con;
                      SqlDataAdapter da = new SqlDataAdapter(com);
      
                      con.OpenWithRetry();
                      da.Fill(dt);
                  }
              });
          }
          catch (Exception e)
          {
              WriteDbError(e, com);
          }
          return dt;
      }
      

      I know that you can configure the enterprise library to use settings from the web.config. I decided to use hardcoded “variables” because they do not change (much). Please let me know if you have more improvements for the code above. I have a simple GetConStr() method which just returns the connection string from the web.config file.

      So this code will solve about 99% of your azure timeouts!

      Good luck! Let me know your opinion in the comments!

      ps. Happy new year!

      Shout itkick it on DotNetKicks.com

      Develop a Windows Phone 7 application on Windows 8.1

      $
      0
      0

      As mentioned in the post “After 4 months working with the Nokia Lumia 920 and Windows Phone 8” I build a really simple flashlight application for Windows Phone 8. According to AdDuplex (27th of December 2013) there is still a 21.7% of all Windows Phone users which run Windows Phone 7.x So I decided to make this tiny flashlight application also available for those 21.7%. It is a small app so it should be rather easy, don’t you think? Well to summarize, it is not! Perhaps just because my CPU does not support SLAT (Second Level Address Translation) so I have to debug on a Windows Phone device (which runs version 7 or 8)

      clip_image004

      When you run Windows 8, you can not develop a windows phone 7.x application and test it on a device. You need Windows 7, Visual studio 2010 or 2012, Zune and the WP SDK. I have tried everything to get it to work on Windows 8.1 x64 as you can read on this StackOverflow topic “Register Windows Phone 7 as developer phone” I have added firewall rules, ran all windows updates, have the latest version of SDK’s, visual studio updates etc. Even when you have registered a Windows Phone 7 as developer phone, you get this error 0x80070103

      image

      In order to be able to develop a Windows Phone 7 application on a Windows 8.1 machine, you need SLAT (to run the wp emulator) or.... a virtual machine! Hyper-V is build in by default in Windows 8 but also no valid option because it also requires SLAT support. So I installed Vmware Player/workstation (Oracle’s Virtualbox is also an option) and installed Windows 7 on it with Zune 4.8 and the Windows Phone 7.1 SDK but first the Visual Studio 2010 Express for Windows Phone.

      image

      I personally ran into an other issue. I had the vm on an external usb harddrive. And somehow there was a read/write error so my vm became corrupted. I had to ‘upgrade’ my vmware player to vmware workstation to run vmware-vdiskmanager. The solution was online in the knowledge base of vmware to fix the corrupted vmdk file.

      A small side note about Visual Studio 2010 express for Windows phone by the way is that you cannot install nuget for it! So please keep in mind that you might want to use a better/larger version of Visual Studio in your VM.

      Good luck developing Windows Phone 7 applications on your Windows 8.1 host machine!

      Working with the Dymo label sdk on Windows 2012 server

      $
      0
      0

      Dymo has some great label printing hardware and has a nice .Net SDK. It seems that they are moving away from the .Net SDK and more towards the JavaScript SDK. In my situation I wanted to host a small Rest service on a Windows 2012 server so that I can make an Ajax call with jQuery to it to print a label from my web application. So it is a kind of printing proxy with REST. We had previously only Internet explorer support in our web application, so using the Active X component was easy for us. Though it required a client installation and the client to configure the network shared printer.

      The strange thing is that this code looks good at first sight. Also if you compare it with the Dymo label code. It even works great on my machine, but when I put it live on our production server it failed. No exception or whatsoever, but it simply said that there is no label writer.

      StringBuilder sb = new StringBuilder
      var label = DYMO.Label.Framework.Label.Open(System.Web.HttpContext.Current.Server.MapPath(@"~/Content/thelabel.label")); // mvc webapplication
      label.SetObjectText("Address", sb.ToString());
      label.Print(ConfigurationManager.AppSettings.Get("printername"));
      // printername = \\pcname\dymo

      Even when I list the label printer, it does not show up in the list. Printing with the default label printing software from dymo (version 8.x) works great on my machine and the server, but not by code.

      StringBuilder sbPrinters = new StringBuilder();
      DYMO.Label.Framework.Printers p = new DYMO.Label.Framework.Printers();
      foreach(var printer in p.ToList())
      {
          sbPrinters.AppendLine(printer.Name);
          sbPrinters.AppendLine(printer.ModelName);
          sbPrinters.AppendLine(printer.IsConnected.ToString());
          sbPrinters.AppendLine(printer.IsLocal.ToString());
          sbPrinters.AppendLine("-==========-");
      }
      return sbPrinters.ToString(); // empty...

      I have tried an Asp.Net web application 4.5 with WebApi on Windows 2012 and a 4.0 Webforms application on Windows 2003. Both did not work. So what is wrong? I used the build in Visual Studio development server and on both windows servers (2003 and 2012) I used IIS. So that might be the problem. I have heard about Katana and OWIN and started a small test project with this guide. Somehow it works when you are not using IIS! I also tried Asp.Net impersonation in the web.config. Maybe running in full trust works, but I prefer a tiny Windows Service with Owin. So go check out the project page of Katana on codeplex or simply pull down this Nuget package of Microsoft Owin. This Channel9 video of 43 minutes is also a great online source to learn more about the Katana project, OWIN for Asp.Net.

      Good luck with the Dymo .Net SDK!

      My migration from BlogEngine to Miniblog

      $
      0
      0

      Mads Kristensen created BlogEngine.Net back in 2007. I have tested Dasblog, Wordpress and imageBlogEngine.Net and decided back in 2010 that BlogEngine was my blogging platform of choice. But now in 2014 when responsive design, JSON, HTML5, CSS3 is all well known and supported. I decided to migrate to a new and minimalistic blog platform. It is called MiniBlog and hosted on GitHub. I really like the project’s name and goal. It has less overhead and is really fast! It is based on bootstrap, so responsive by default.

      So the requirements for me for my new blogging platform is:

      • .Net C#
      • Bootstrap theme(s)
      • Lightweight
      • Fast
      • Live writer integration
      • RSS feeds (to feed to feedburner)
      • SEO friendly
      • Mobile friendly
      • Azure hosting support

      Miniblog has it all. Because I am a lazy bastard programmer, I will call BlogEngine.Net BE and Miniblog MB. Here is how I moved from BE to MB:

      1. Forked MB

      So that I can contribute and give back to the community. And I can keep my own branch and have a local repository.

      2. Moved App_Data posts

      Copied all posts from BE to MB. But MB could not found my categories.

      3. Formatted BE data for MB

      Cloned this formatter to my desktop and uncommented line 17 and commented out line 18 of program.cs and renamed the folder parameter to origin in order to get it to run.

      4. Made a custom theme

      I have just copied one of the existing theme’s and made adjustments to the CSS (and razor view) You really have all freedom with this blogging platform

      5. Moved login credentials

      The default login is demo, demo and is stored in your web.config. You can change it, but perhaps accidentally commit it to GitHub, so follow this guide to move it to a separate authentication.config and exclude it in your gitignore.

      6. Google Analytics

      A plain installation of MiniBlog does not include Google Analytics “integration”. So you manually have to add the tracking code in your custom theme (from step 4) It is a good time to move your old Analytics to the new “universal analytics”. Add the snippet before your </head> tag.

      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXX-X');
      ga('send', 'pageview');

      7. Syntax highlighter

      To make the code snippets more readable I use this javascript library to enable syntax highlighting. At first, I took the wrong javascript files from the zip. I found the solution on this post about xregexp not defined.

      8. Custom pages

      MB is by default just a blogging platform and does not have custom pages for about and/or contact. It is better to add them in the view folder, but then you might have to do some work for better routing, so I added an about.cshtml and contact.cshtml to the root of the project. You can reference the theme’s shared layout there to make it match the rest of the sites layout.

      9. Social sharing

      This is also related to point 4. It gives visitors the option to share your posts on social networks which can give you a better reach. You can use AddThis or something similar. Or use the official plugins from Facebook and Twitter but that includes more javascript and dom manipulations which cause more load on server and client side. Which gives you less points with Google’s Pagespeed. So I combined the url’s from Hanselman’s post and the icons from Flaticon with the “embed resource as base64” option from web essentials Visual Studio extension.

      10. Ads

      I included a small javascript reference from developer media (previously lake quincy media) to add some ads to the posts (to try to earn back the money for my hosting bill) and included it in my theme, but I am still looking for the best performing ad dimensions.

      11. Url-rewrite

      I am using this free extension of IIS to rewrite some url’s and have added this rule to include the www subdomain:

      <rule name="Add WWW prefix" stopProcessing="true"><match url="(.*)" ignoreCase="true" /><conditions><add input="{HTTP_HOST}" pattern="^jphellemons\.nl$" /></conditions><action type="Redirect" url="http://www.jphellemons.nl/{R:0}" redirectType="Permanent" /></rule>
      MB has default rules to remove the www subdomain (which I disabled) and has a rule to remove the .aspx which BE has, to get cleaner url’s


      Have I missed something? What changes did you make when moving to MiniBlog?


      Adding numbers to number table

      $
      0
      0

      I have a table filled with numbers. It is a table with the name numbers and there is only one field named ‘num’ which is an integer (so max value is 2.147.483.647 as seen on MSDN) and the integer is  an identity and unique.

      2014-03-05 12_10_47-VM530.ssinternational - dbo.numbers - Microsoft SQL Server Management Studio

      The table just contains numbers from 1 until 10.000. I use it to inner join, for instance:

      You can have a table with a row: productA is 10 times in stock. You can then inner join the numbers table if you need 10 rows of productA.

      select * from products 
      inner join numbers on num <= stock

      But I only had 10.000 rows in it and encountered a bug in my system because 10.000 was not enough. So I had to increase it. I have found several solutions to create a numbers table. But no snippet to update an existing number table.

      So here is my snippet to add additional numbers to your number table:

      begin transaction
      SET IDENTITY_INSERT [numbers] ON
      
      DECLARE @i INT;
      SELECT @i = 10001;
      SET NOCOUNT ON
      WHILE @i <= 1000000
      BEGIN
          INSERT INTO [numbers] (num) VALUES (@i);
          select @i= @i + 1;
      end;
      
      SET IDENTITY_INSERT [numbers] OFF
      commit
      
      Good luck!

      FTPES with self signed certificate

      $
      0
      0

      Here is a small C# code snippet to upload an XML file to an explicit SSL secured FTP server.

      When you search nuget for FTP you will get:

      image

      But which one do you need? Not all of them support FTPS. Well the checkbox gives it away.

      If you search for FTPS you will only get these seven results (at this moment):

      image

      So you need the System.Net.FtpClient from https://netftp.codeplex.com/

      And here is the C# code to upload an XDocument to an FTPS server:

      private void UploadFile(XDocument xDoc, string filename)
      {
          using (FtpClient fc = new FtpClient())
          {
              fc.Credentials = new NetworkCredential(username, password);
              fc.Host = hostname;
              fc.EncryptionMode = FtpEncryptionMode.Explicit;
              fc.ValidateCertificate += fc_ValidateCertificate;
              fc.Connect();
              fc.SetWorkingDirectory("/uploaddir");
      
              using (var ftpStream = fc.OpenWrite(filename, FtpDataType.Binary))
              {
                  if (ftpStream != null)
                  {
                      xDoc.Save(ftpStream);
                      ftpStream.Close();
                  }
              }
          }
      }
      
      static void fc_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
      {
          e.Accept = true;
      }
      

      Self signed certificates will otherwise always cause an exception in the ftp libraries because the certificates are not really valid. So you manually have to “validate” it.


      Good luck!

      Visual Studio: Reference to higher version or incompatible assembly cannot be added to the project

      $
      0
      0

      I had this error “A reference to a higher version or incompatible assembly cannot be added to the project” during my Windows Phone development. I wanted to add some dll’s because there are no nuget packages for smaato, mobfox etc.

      http://i.imgur.com/YsNnEWF.png

      At first I thought that it was because the dll’s were not build as portable class library. But then I found this other source online which gave me the correct and simple answer: Windows blocks the downloaded dll’s by default. You have to unblock it by going to the properties of the dll.

      You can also unblock with powershell by using Unblock-File

      So perhaps the dialog of visual studio should tell me that it is impossible to add a reference to a blocked dll.

      Good luck!

      Serving ads for Windows Phone 8

      $
      0
      0

      To start serving ads in your Windows Phone application you can install the Microsoft advertising SDK. But I believe it is not mandatory. You do not need to reference it in your project. So please take a look at the screenshot below and make sure you do not check that box!

      2014-04-25 15_30_38-Reference Manager - Zaklamp

      I recommend using the (not yet final) Adrotator V2. It is the successor of V1 and has an XML configuration file which can be put somewhere online (remote) so that you can edit advertising preferences without needing to update the whole app and push it to your users.

      You can get it from nuget as long as you make sure that you can view the pre-releases or put this in the packagemanager console:

      Install-Package AdRotatorWP -Pre

      That will pull down the package. The readme file will open in a tab and tell you to manually add more DLL’s for mobfox, smaato etc. (only adduplex is included because they have a nuget package).

      You should mark your XML config file in the project explorer as content and copy to output always and check the app’s permissions, because mobfox requires <Capability Name="ID_CAP_IDENTITY_DEVICE" />  as found on http://wpunifiedad.codeplex.com/discussions/436059

      It took me a while to figure that one out. You have to add this namespace in the XAML in order to use the adrotator component.

      <phone:PhoneApplicationPage
          xmlns:adRotator="clr-namespace:AdRotator;assembly=AdRotator"
      ...>

      Good luck!

      Microsoft Surface 3 Pro can be my next developer machine

      $
      0
      0

      The Surface 3 pro will be available in 5 different versions:Surface Pro 3

      • 64Gb  i3 cpu 4gb ram €  819,-
      • 128Gb i5 cpu 4gb ram € 1019,-
      • 256Gb i5 cpu 8gb ram € 1319,-
      • 256Gb i7 cpu 8gb ram € 1569,-
      • 512Gb i7 cpu 8gb ram € 1969,-

      These prices are Dutch and include VAT. I have read about the difference in RAM not on the Microsoft website but at the zdnet site.

      For an awesome development setup you really want an external 4k monitor. The Surface 3 Pro should be able to output 4k which is at least 3840 * 2160 according to Wikipedia. The cheapest 4k monitor in the Netherlands is this Samsung for € 600,- 

      U28D590D 4 R Perspective Black

      Microsoft also has an dockingstation available which is really required if you work behind your desk all day and commute with the Surface. There is no final price info for it in euro’s but I expect it to be € 200,-. It has 3 usb 3 ports, 2 usb 2 ports, ethernet and audio. We will have to wait until the 20th of June for more detailed info.

      For commuting you’ll want a cover. Type- or touchcover depends on your preference. But that is an additional 120 or 130 euro’s.

      To connect an external monitor you need an adapter. For my full High definition monitor that’s an mini display port to HDMI. For the mega-awesome 4K Samsung that is a mini-display to display port.


      As developer you really want to have at least 8gb ram in your device, so to round up:


      Surface 3 pro with i5, 8gb ram and 256gb storage  € 1319,-

      Touch or type cover € 120,-

      Docking station € 200,-

      Display adapter for my Full HD display (mini dp to hdmi) € 15,-

      Samsung monitor € 600,- (optional perhaps stick with 1080p full hd display first)

      Display adapter (mini dp to dp) € 13,-


      I already have a nice Logitech K800 wireless keyboard with darkfield mouse. So total investment without the awesome 4k display would be € 1654,- (without cable 1639)

      If you would buy it in the states it would be:

      • Surface        $ 1299,-
      • Dockingstation $  200,-
      • Cover          $  120,-
      • Total:         $ 1619,- (in euro: € 1187,-)

      Buying it in the states will save you € 452,- That is almost the price of a two way ticket to get it yourself and have a nice city trip.

      Have fun with the Microsoft Surface 3 Pro!

      Viewing all 132 articles
      Browse latest View live