Wednesday, May 16, 2012

SQL Express Connection Times Out Even Though It is Up

Symptom:

I can access the local SQL Express server instance without a problem using the SMSS, but from my application the SQL connection times out almost immediately.

Cause:

In my situation, it was a connection string issue. In production I use a mirrored connection. So just out of a laziness, I just change two of the hosts in the connection string to be the same.

Like this,

Data Source=localhost;Failover Partner=localhost;Initial....

Apparently the driver does not like this type of conneciton string and give you an immediate timeout error.

Fix

Just remove the Failover Partner part and try. It always does the trick to me.


Monday, May 14, 2012

WFC Services Runs OK on Visual Studio Web Server But Not on IIS When Deployed


Symptom:

You have created an WCF "web" service. It debugs and runs fine on the Visual Studio's web server, but when deployed the directory to the IIS 7 (even on the same local machine) you get a script error.

The Root Cause

The WCF is not fully enabled on your IIS 7.

The Fix

The complete fix is from this web site at Microsoft. http://msdn.microsoft.com/en-us/library/ms752252(v=vs.90).aspx 


  • Open the IIS manager and Go to the Default Web Site, Double-click Handler mappings in the Features View.
  • In the list of application mappings, verify that the .svc file for the .NET Framework in use (2 or 4) is mapped to the aspnet_isapi.dll. If the file has not been mapped:
  • Click Add Managed Handler.
  • Type *.svc into the Request path:.
  • Type System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 into the Type textbox.
  • Type svc-Integrated into the Name: textbox.
  • Click OK.
  • Click Add Script Map.
  • Type *.svc into the Request path:.
  • Type %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll into the Executable: text box.
  • Type svc-ISAPI-2.0 into the Name: text box.
  • Under the right "Actions" Panel, select "View Ordered List" then Using the Move Up/Move Down controls, ensure that the managed handler (svc-Integrated) appears before the aspnet_isapi (svc-ISAPI-2.0) handler in the list.
  • Click OK.
  • Give it a shot.


Visual Studio 2010 Reloads Microsoft.VisualStudio.IDE.ToolboxControlsInstaller,ToolboxInstallerPackage'{2C298B35-07DA-45F1-96A3-BE55D91C8D7A} Every Time

Symptom

When opening a forms designer on Visual Studio the following toolbox loads each time and it takes a long time by loading the toolbox with the following information.

Microsoft.VisualStudio.IDE.ToolboxControlsInstaller,ToolboxInstallerPackage'{2C298B35-07DA-45F1-96A3-BE55D91C8D7A}

Possible Solution:

There are various options on this, and the best discussion about this is at this URL:  But it appears that this is related to Silverlight SDK corrupting some data in the SDK based on this post.

There are other discussions on this post.

In my specific case, setting

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Packages\{2c298b35-07da-45f1-96a3-be55d91c8d7a}\Toolbox\DefaultItems to 0

made it worse.  I cannot recommend this.

Instead try un-installing and re-installing the Sliverlight SDK in the order of versions to fix the toolbox issue. Namely remove 5.0 SDK and 4.0 SDK then install the 4.0 first then 5.0 if you are still (having to) coding with Sliverlight.

As with anything, approach your fix with a big caution when dealing with config issues like this. Have a good back-out plan like backing up the registry settings etc.

Thursday, May 10, 2012

ATT Momentum 4G Adaptor Blue Screens Windows 7 X64

Symptom:

When you plug in ATT Momentum 4G (Sierra Wireless Momentum), you get a blue screen (with memory violation from a driver) when the driver in being installed.

Root Cause:

I do not know exactly which driver causes this, but...

It appears that the Sierra driver is not compatible with the USB-3 interface (at least on my ASUS u46s). Try plugging this into a USB-2 interface slot and start the installation over again.

Also, in my situation, I had to call the ATT's automated activation phone line to activate the SIM in it.







Thursday, April 26, 2012

Collecting PDF Form Data with ASP.NET C#

I recently had to investigate the technique to capture the form input data collected on Adobe PDF for radiological procedure report results.

This, though very simple, information was scattered around all over the places so I can provide you the gist of what you need to do by means of a simple demo code.
  • First you will need to use the PDF Form Editor, for example Adobe Acrobat Pro. I am sure there are a lot of different ones.
  • Next you either scan a form or create one which output the usual .doc file.
  • Import the document and edit the form using the PDF form editor, drag and dropping the fields.
  • Finally add a submit button with a submit action of http://localhost/xfdf
  • On Visual Studio, create the xfdf web project and you can add the following code in Page_Load of Default.aspx
public partial class xdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var name = "junk.xfdf";
        string filename = Path.Combine(Server.MapPath(""), name);
        using (FileStream fs = new FileStream(filename, FileMode.Create))
        {
            byte[] bytes = new byte[8192];
            int bytesRead;
            while ((bytesRead = Request.InputStream.Read(bytes, 0, bytes.Length)) > 0)
            {
                fs.Write(bytes, 0, bytesRead);
            }
        }
    }
}
  • Compile above code.
  • Submit the PDF form to the URL
Then if you open junk.xfdf on your text editor, you will see something like this. The key part is that you will see the field and value elements in the XML. From this point it is quite easy to parse this stuff using the XDocument class and LINQ.

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"
><fields
><field name="Heart Rate"
><value
>10</value
></field
><field name="Submit"
/></fields
><ids original="BFF11731D28F744F901901CF60BBED7A" modified="B0328D96D4E3F242A93BC5512C7B97E6"
/></xfdf
>

Monday, April 09, 2012

Getting XTIDE Up on Joyent SmartMachine (Solaris 11)

This is my note on getting the XTide (learn more) up on the Joyent SmartMachine on which I am running various personal web projects. My XTide was previously hosted on a shared Linux machine (i.e., no root access) before but the provider upgraded the Linux and then it broke. Since I now have an Intel Solaris 11 virtual machine of "my own," I have decided to transition to this server (as I find time, of course.) Installing and configuring XTide on a shared machine was a real hassle as they did not have X11 installed and they won't install it for me, but now with the virtual machine in which I have the "root" things are becoming much easier, in addition there are a lot of pre-built installs that's available (still require the root access.) {Why Joyent SmartMachine and Solaris? Don't ask. But I am extremely satisfied with it. }

Perhaps you may have the same problem and here is how I got around the issues.

Note that I am only interested in running this as a command line to compute the tide and graphics in the area I surf using a cron job. So if you have an X-Windows issue, this article won't help much.


Getting It Installed

Getting it installed is fairly simple.
  • The page http://www.flaterco.com/xtide/files.html tells that on Solaris you go to Blastware.COM, but almost all of the mirror sites it points to are broken. Instead, if you go to http://www.opencsw.org/packages/xtide/ it is still avilable. The maintenance of this stopped around 2.10 (in 2008) but for my purposes, it is OK. Someday, when I have more time, I may volunteer to contribute to Opencsw to maintain this. Not now...
  • It comes with required libraries, and also the original harmonics and wvs files it was built with in /opt/csw/share/xtide 
  • If you don't know what I am talking about but you have the root access to the machine, just follow the instructions on the OpenCSW web site, install the pkgutil installer first as a root (if you don't have) and then install the xtide with it. You would be all set in a matter of 5-10 minutes. And if you still don't know what I am talking about, then it is best to ask your IT admin buddy to get that done as it can affect other OpenCSW packages other people may be using on your machine. 
Getting it to Run
  • "Out of the box" by typing in {tide -l "princeton"} it did not run. In fact it threw an exception about saying  the following:

    XTide Fatal Error:  BAD_OR_AMBIGUOUS_COMMAND_LINE

    but do not dismay yet...!
  • Here is what I have done to get it going!
The "tide" command on /opt/csw/bin/tide is a shell script which, in turn, will run tide.bin after "tide" sets various environment variables. There appears to be an issue with the WVS_DIR environment variable and if only have the HFILE_PATH it works (in other words comment out WVS_DIR definition in the tide script), and it will output the tide. The graphics output also worked.

To test if anything works, you can first only EXPORT the HFILE_PATH in your shell then run /opt/csw/bin/tide.bin directly like this.

HFILE_PATH="/opt/csw/share/xtide/harmonics.tcd"
export HFILE_PATH
/opt/csw/bin/tide.bin -l "princeton"

The Harmonics Database Location Names Have Changed

In my old script I had -l "half moon bay." This time it did not work as the program could not find the station name. So be sure that you look at the Location List (http://www.flaterco.com/xtide/locations.html)  that matches your Harmonic file you've downloaded.

Hope this helps in your situation.





Saturday, April 07, 2012

ASP.NET GridView and LinqDataSource Stuff...

The DataGrid is one of the components I use quite a bit in my line of work, and they are convenient.

I have also been using LINQ quite a bit. It is a significant time saver as well as making my code more easier to understand. But until today I never bothered to use LinqDataSource just because I did not spend time to learn a bit about it. Instead I always built the DataSets using the designer. The problem with the Datasets for me is that it does not show me exactly what I am querying easily.

Before I get into that, I have to tell you also that if your requirement is very simple, then you can feed the result of the Linq query directly to the GridView (or other data binding controls.) This might be a great way to bind the pull down menu or a list view with small number of selections.

For example,

var customers = from c in context.customers select c;
gridview1.DataSource = c;

And that really all it takes to feed a GridView. For more information on this, learn from this MSDN page.

But this won't allow you to sort or page the grid. For that purpose you need to attach a LinqDataSource. You can easily do that by:

  • Defining the LinqToSQL object in your project, or pull one in from other assembly
  • Dragging and dropping the LinqDataSource component on to of the GridView. The wizard will show you which of the LinqToSQL database context object to use.

Well that's great, but I really do not want to use the connection string that's built into Web.config. In my case, I pull the connection string common to all my applications from my own company's registry set. But at any rate, you would assign a newly created data context to e.ObjectInstance of the event argument.

So here is another trick.

  • Define an event processing method for ContextCreating event.


       protected void LinqDataSource1_ContextCreating(object sender,
           LinqDataSourceContextEventArgs e)
        {
            string myConnectionString="your connection string";
            e.ObjectInstance = new MyDataConext(myConnectionString);
        }




Sunday, March 25, 2012

Mac Lion: ssh hangs

Symptom:

On Mac Lion (10.7.3), when you try 'ssh' it times-out. You know you have the proper login and host parameters because it works from other computers (say Linux or Windows putty, or even running putty on the same Mac!)

Cause:

I do not know, but it appears that the Mac Lion SSH handles UTF-8 character sets in the manner that the remote side do not like.

There is nothing wrong with your network or network provider. Something wrong is introduced in Lion.

Fix:

Essentially finding a line in /etc/ssh_config file that says LANG LC_* should just be commented out. If you do not know exactly what I am talking about the following is the steps to accomplish this.

  1. Open Terminal
  2. sudo vim /etc/ssh_config
  3. Supply your password
  4. Type in below, including the first /
  5. /LANG LC_
  6. This will take you to the line where the problem is
  7. Hit the left arrow key several times,  until you are at the start of the line.
  8. Type i to insert
  9. Type # to comment out the line
  10. Press ESC to exit the insert mode
  11. Type wq (means write quit) to save the file and exit vim
  12. Now close the Terminal, Re-launch it and try ssh again
If you do not want to all of this, simply download other SSH clients and use them.