This comes up rarely, but is a little esoteric so it is worth noting. You want to update values in one table with a value from another table. Use the following syntax:
UPDATE TableOne
SET ColumnOne = T2.ColumnFromT2
FROM TableOne T1
Join TableTwo T2
On T1.CommonId = T2.CommonId
Monday, January 27, 2014
Tuesday, January 21, 2014
Updating code to use modern web standards - HTML5 and XHTML5
I am working on several sites that were developed 5-10 years ago, and they are all having compatibility issues with the newer versions of IE. Since IE 8, the answer has been the Compatibility Mode function. However, this button and its associated function is being phased out. It's now buried in the menu of IE 11, so I'm concerned about it's going away with IE 12. I'm starting to research and fix the sites so that they display properly in modern browsers.
The majority of the problems is that the site "just looks bad" without compatibility mode. The first step is to change the markup, so that it meets current standards. Using Visual Studio, I'm validating all markup with XHTML5. I'm not introducing any new HTML5 tags. I'm simply changing the existing markup so that it isn't flagged by the validator. I'm also fixing any display issues that crop up.
What is HTML5 and XHTML5? HTML5 is the latest and greatest version of HTML. Modern browsers support most of the standard. Older browsers support only the stuff that has been around forever (tables and input tags and such). XHTML5 is the XML version of HTML5. It is basically the same thing except that XHTML5 is slightly stricter. For example, HTML5 will let you write a tag and not close it. XHMTL5 requires lowercase letters just like XML does.
I think XHTML5 is appropriate to validate your markup with since it is a bit more strict, and forces you to write tidier markup.
The majority of the problems is that the site "just looks bad" without compatibility mode. The first step is to change the markup, so that it meets current standards. Using Visual Studio, I'm validating all markup with XHTML5. I'm not introducing any new HTML5 tags. I'm simply changing the existing markup so that it isn't flagged by the validator. I'm also fixing any display issues that crop up.
What is HTML5 and XHTML5? HTML5 is the latest and greatest version of HTML. Modern browsers support most of the standard. Older browsers support only the stuff that has been around forever (tables and input tags and such). XHTML5 is the XML version of HTML5. It is basically the same thing except that XHTML5 is slightly stricter. For example, HTML5 will let you write a tag and not close it. XHMTL5 requires lowercase letters just like XML does.
I think XHTML5 is appropriate to validate your markup with since it is a bit more strict, and forces you to write tidier markup.
Tuesday, January 14, 2014
Browser definition files
Deep within the .NET framework installation is a folder full of what are called browser definition files. For example this folder for version 4 forward is here:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers
It is full of xml configuration files with an extension of .browser. These files tell ASP what Javascript and HTML to render for each browser and version.
When IE 10 was released there was an issue with certain things not working. An example was a DropDownList control not posting back. It turns out that there was a bug in the browser definition file for IE in the .NET framework. This link describes this:
http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx
Microsoft created a hotfix that updates these files and fixes the bug when you run it on the server hosting the site. I was really hesitant about deploying a hotfix to a production web server. My preference is to wait for hotfixes to be put into at least a cumulative update if not a service pack (This doesn't appear to have happened at the time of this writing). So, I added the updated IE browser definition file directly to the Visual Studio web project by adding a special ASP.NET folder named App_Browsers. I then added the updated .browser file from the link above to this new folder. After I published the site, the issues I had disappeared.
UPDATE:
I ran into similar problems with IE 11. However, I could not find the browser files for IE 11 anywhere. It looks like Microsoft prefers you to go the hotfix route. So I installed the following hotfix on the web server, and everything then rendered correctly.
http://www.microsoft.com/en-us/download/details.aspx?id=39257
KB2836939
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers
It is full of xml configuration files with an extension of .browser. These files tell ASP what Javascript and HTML to render for each browser and version.
When IE 10 was released there was an issue with certain things not working. An example was a DropDownList control not posting back. It turns out that there was a bug in the browser definition file for IE in the .NET framework. This link describes this:
http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx
Microsoft created a hotfix that updates these files and fixes the bug when you run it on the server hosting the site. I was really hesitant about deploying a hotfix to a production web server. My preference is to wait for hotfixes to be put into at least a cumulative update if not a service pack (This doesn't appear to have happened at the time of this writing). So, I added the updated IE browser definition file directly to the Visual Studio web project by adding a special ASP.NET folder named App_Browsers. I then added the updated .browser file from the link above to this new folder. After I published the site, the issues I had disappeared.
UPDATE:
I ran into similar problems with IE 11. However, I could not find the browser files for IE 11 anywhere. It looks like Microsoft prefers you to go the hotfix route. So I installed the following hotfix on the web server, and everything then rendered correctly.
http://www.microsoft.com/en-us/download/details.aspx?id=39257
KB2836939
What is ASP.NET Impersonation?
When using Windows authentication, the User property of the HttpContext will be set to whoever is browsing your web application. This allows a programmer to do certain things based on the user who is currently accessing the system. However, the current user will not be used to determine access to file resources or connect to a database for example. (I believe the application pool identity is used by default). What if you want to use the current user for this other access?
You need to impersonate the current user when accessing these resources. Simply put the following in your web.config file:
You need to impersonate the current user when accessing these resources. Simply put the following in your web.config file:
<system.web> <identity impersonate="true" /> </system.web>You can also specify a username and password to use. I'm not sure the value in this since you could always just use the app pool identity, but if you need to, do this....
<system.web> <identity impersonate="true" userName="Steve" password="Supersecret" /> </system.web>
Friday, January 10, 2014
AJAX Enabled WCF Service with Windows Authentication
Let's say you have a WCF Service that you are calling from jQuery code. Everything works fine until you set up Windows Authentication. Then it blows up. The problem is that the binding has to be configured to work with Windows Authentication. Let's first look at the endpoint in the web.config file. Take a look at the binding attribute. It should say "webHttpBinding". WebHttpBinding means that your web service responds to HTTP requests. This is necessary because this is the only way jQuery can call your service. In fact, I believe Visual Studio sets it in this way when you added the AJAX Enabled WCF Service rather than a plain old WCF Service. However there is no configuration for the WebHttpBinding itself, which means it just uses its default configuration which I believe is configured to use anonymous authentication. So we need to configure the WebHttpBinding to use Windows Authentication by putting the following nodes inside the system.servicemodel node:
<bindings> <webHttpBinding> <binding> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows"></transport> </security> </binding> </webHttpBinding> </bindings>
Tuesday, January 7, 2014
Testing Android apps using a Nook HD
I've been doing some android development on the side lately, and have been using my phone for testing since my experience with emulation has been terrible so far. However my phone is an old Gingerbread phone and there were some features in the newer versions of Android that I wanted to take advantage of. I have a Nook HD which is built upon the Ice Cream Sandwich version of Android, so I took on the task of using the Nook to test.
It wasn't the easiest experience to configure this, so I wanted to document this while it is fresh in my mind. First you need to read this document:
https://nookdeveloper.zendesk.com/entries/21943338-nook-developer-start-up-guide
Start with the standard Android dev environment: The ADT bundle you download at Google.
You have to install something called the Nook SDK which you can install by using the Android SDK Manager tool inside of Eclipse. It's in the Window menu. Then, follow directions in the document. The SDK Manager tool looks like it is also used to update your dev environment and a bunch of stuff was already selected, so I just installed all of that along with the Nook SDK. But I really think the Nook SDK was the only thing I needed checked.
You do need to set the PATH variable.
This is where things get stupid. If you're just using the emulator, I don't think you need this, but of course I wanted to run apps directly on the device. The Android Debug Bridge (adb) is some kind of command that Eclipse uses to side load apps onto your device for testing. The document shows you how to test to see if your device is seen by adb. Mine wasn't seen (of course). It suggests you install some special drivers. To get the drivers, you have to register as a Nook developer and get approved. There are silly questions that you just make up answers to and wait 8 hours, and then you're in. After that, download the drivers. In Device Manager, I had to "Uninstall the device", and then click on the device that was labeled BNTV400 (not MyNOOK) and then I install (or maybe it was update) the driver and browse to the driver you downloaded. Once this was done, adb could see the device. I did have to adb kill-server, adb start-server, once before it would work with Eclipse.
I'm actually quite surprised I got this working.
It wasn't the easiest experience to configure this, so I wanted to document this while it is fresh in my mind. First you need to read this document:
https://nookdeveloper.zendesk.com/entries/21943338-nook-developer-start-up-guide
Start with the standard Android dev environment: The ADT bundle you download at Google.
You have to install something called the Nook SDK which you can install by using the Android SDK Manager tool inside of Eclipse. It's in the Window menu. Then, follow directions in the document. The SDK Manager tool looks like it is also used to update your dev environment and a bunch of stuff was already selected, so I just installed all of that along with the Nook SDK. But I really think the Nook SDK was the only thing I needed checked.
You do need to set the PATH variable.
This is where things get stupid. If you're just using the emulator, I don't think you need this, but of course I wanted to run apps directly on the device. The Android Debug Bridge (adb) is some kind of command that Eclipse uses to side load apps onto your device for testing. The document shows you how to test to see if your device is seen by adb. Mine wasn't seen (of course). It suggests you install some special drivers. To get the drivers, you have to register as a Nook developer and get approved. There are silly questions that you just make up answers to and wait 8 hours, and then you're in. After that, download the drivers. In Device Manager, I had to "Uninstall the device", and then click on the device that was labeled BNTV400 (not MyNOOK) and then I install (or maybe it was update) the driver and browse to the driver you downloaded. Once this was done, adb could see the device. I did have to adb kill-server, adb start-server, once before it would work with Eclipse.
I'm actually quite surprised I got this working.
Subscribe to:
Posts (Atom)