NULLs in MongoDB

Posted by Dan | Posted in Databases, MongoDB | Posted on 08-10-2011

0

By default, the C# driver’s serializer takes a null value and assigns a default, rather than just writing the word NULL in the collection when inserting.

So if you had a an object that had 50 properties, only set 1 value in it, and passed it to MongoDB, it would insert all 50 properties, which would be wasteful (depending on how you looked at it).

One can decorate the property with the [BsonIgnoreIfNull] attribute and will not write that element to the db if it’s null. However, if you don’t always want to use this property, one can set it once (and forget it) by creating a MongoDB “ConventionProfile” across the entire application. We have this setup in the Global.asax.cs so it gets created when the application is loaded:

var profile = new ConventionProfile(); 
profile.SetIgnoreIfNullConvention(new AlwaysIgnoreIfNullConvention()); 
BsonClassMap.RegisterConventions(profile, t => true);

However, even with that, it only appears that it does this only for strings that are null. If you have a property that’s Boolean, Integer, or Date, it will still write the elements to the database, setting Booleans to Falses, Integers to 0, and Dates to an ISO timestamp. It does this partly because these data types don’t implement a NULL property, so they can’t be null. To “make” them NULL, you have to use the question mark after the data type, like so:

bool? IsEnabled;
int? MagicNumber;
Date? TimeStamp;

All three are short for:

Nullable<bool> isEnabled;
Nullable<int> MagicNumber;
Nullable<Date> TimeStamp;

Renaming a SQL Server Table (Watch Out)

Posted by Dan | Posted in Databases, SQL Server | Posted on 08-10-2011

0

Sometimes while testing on your local db, one has the habit (I admit to have this in the past) of renaming a table before replacing it. One does this as a quick backup. The problem with this strategy is that it doesn’t rename all of the dependencies. For example, if you had a table formsClients and renamed it formsClients_old, and then restored the formsClients table again (let’s say from an SSIS import), you’ll get something like this:

If we inspect the dependencies, we’ll see that in this case, it’s a foreign key constraint:

Delete Duplicate Rows

Posted by Dan | Posted in Databases, SQL Server | Posted on 07-12-2011

0

If you’ve ever tried to delete two rows that are identical from SSMS, you may come across this little beauty:

To get around this, you have to delete 1 row at a time and use SET ROWCOUNT. So you would do something like

SET ROWCOUNT 1
GO
DELETE FROM users_to_optin WHERE email = 'someone@yahoo.com'

That would delete one record at a time, even if there were multiple instances of ’someone@yahoo.com’.

After you’re done, make sure you set the rowcount back to 0, which turns the limitation off.

SET ROWCOUNT 0
GO

Check out more about ROWCOUNT.

Visual Studio Theme

Posted by Dan | Posted in C# | Posted on 06-08-2011

0

I put together my own color theme with the help of StudioStyles. Theme inspired by TextMate and Sublime Text. Check it out:

Scripting Out SQL Server 2000 Database Objects from SQL Server 2008 Management Studio

Posted by Dan | Posted in Databases, SQL Server | Posted on 06-08-2011

0

If you’re still stuck working with a SQL Server 2000 database, there’s no reason why you shouldn’t be using SSMS 2008 R2. There’s lots of great add-ons for it and provides a rich set of features, aside from merging Query Analyzer and Enteprise Manager.

One thing to watch out for, is that if you script out your database objects, while you’re connected to SQL Server 2000, by default, it will script out TSQL that is compatible only with SQL Server 2008. To switch this, there are two ways:

Tools -> Options -> SQL Server Object Explorer -> Scripting

Database -> Tasks -> Generate Scripts

ErrorDetail I/O Exception: peer not authenticated

Posted by Dan | Posted in ColdFusion, Java | Posted on 06-08-2011

0

Similar to this page, I was getting the following error:

ErrorDetail I/O Exception: peer not authenticated
Filecontent Connection Failure
Mimetype Unable to determine MIME type of file.
Statuscode Connection Failure. Status code unavailable.

Which you get when the JVM has an old version of an SSL certificate. More specifically, I was having problems connecting to ConstantContact, after noticing that they had just renewed their certificate:

Cracking my head open, and trying every solution in the world along what the people posted here, we just decided to reboot the server. This flushed the cache and it worked.

If you can afford to do this, then I recommend it if you want to go for the fastest solution. ConstantContact later provided other possible solutions.

SSIS Data Import from Excel

Posted by Dan | Posted in Databases, SQL Server | Posted on 05-30-2011

0

I’ve always found the SSIS import tool a bit clunky. I tried to import a CSV file and it get crapping out before completing.

- Copying to [dbo].[export] (Stopped)

Messages

  • ·Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column “Email Address” returned status value 4 and status text “Text was truncated or one or more characters had no match in the target code page.”.
    (SQL Server Import and Export Wizard)
  • ·Error 0xc020902a: Data Flow Task 1: The “output column “Email Address” (10)” failed because truncation occurred, and the truncation row disposition on “output column “Email Address” (10)” specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
    (SQL Server Import and Export Wizard)

I sifted through the data, only a few hundred rows, and I could not see anything wrong with it. I made the columns the right type and increased the column size more than the largest number of characters in the fields. I searched Google and Microsoft Forums trying a handful of solutions and nothing worked.

So what did I do? I had enough and just opened the file from CSV, into Excel, resaved it as an Excel 2007. Re-ran the SSIS import wizard to open an Excel file instead of a CSV, and voila. I’m still baffled though, as to what exactly the problem is.

Send A File Path from the Windows Context Menu to App

Posted by Dan | Posted in Automation / Scripting, C#, Windows | Posted on 05-26-2011

0

Here’s an easy way to pass the file path to a console app. I needed a way to right click on a folder or a file, and send the path to a console app, where the app does its thing with the file(s).

To show you what I mean:

When I right-click on “coolbeans” it runs the following console app, which simply displays the path:

The C# app is pretty straightforward. Basically, once you have the file path, you can apply any operations on the file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace dan_rocks
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(args[0]);
      Console.ReadLine();
    }
  }
}

So there’s nothing crazy going on in the above sample. You basically just have to add a few entries to the Registry.

If you want to pass a folder path when you right-click on it, and select the option in the context menu, create a new entry:

HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell

If you want to pass in a file, do the following:

HKEY_CLASSES_ROOT\*\shell

Let’s pass in the filepath to note.exe:

Do that and you’ll see the following:

A Fix For Faulty Visual Voicemail on the HTC Evo 4G

Posted by Dan | Posted in HTC Evo 4G | Posted on 08-15-2010

0

I just purchased the HTC Evo a few weeks ago and was privileged to enjoy the annoyance of a faulty visual voicemail. To summarize my problem:

  • The Voicemail App Widget was NOT showing any new voicemails
  • I was not being notified in the notifications panel when a new voicemail arrived
  • In the Voicemail app, it said “No Voicemails”

This was after me fumbling through every conceivable option in Android. I had voicemail notifications turned on and my voicemail was set. I could still check my voicemail manually by holding the number 1 key – but this was very annoying. I went to a Sprint support person, and we were trying out various settings for about 20 minutes without success. Finally, he suggested that I turn off the phone, take out the battery, and then wait 30 seconds to put the battery back on and start it. That did nothing, however.

I was thinking that maybe my recent update to Froyo had anything to do with it. Also, maybe the fact that my number was ported from an iPhone on AT&T. So I tried to look for solutions online. I found two forum posts from people having the same problem:

What Worked For Me

So it seems there are three types of solutions (from what I read in these posts). The third worked for me.

Solution #1: (Quoting Zera from the evo4gforum):

1. Ok, open your voicemail program, it will likely show the “No voicemails” screen.
2. Hit Menu>compose then click in the “To” field at the top to bring up your keyboard.
3. Type this exactly: activate@vvm.sprint.com
4. Hit record, then hit stop.
5. Hit send.

My voicemails I’d been leaving myself all morning to test flooded in within 5 seconds, and the voicemail icon is showing the number of voicemails as well.

Solution  #2: (Quoting peakay from evo4gforum – but forum mod states that the Ghost number is unique and you need to get that from Sprint) :

I just had this problem and nothing I did or looked up help (including the excellent help posted here by the moderator). got off of the line with Sprint and apparently there is sometimes a “Ghost” number set up on your phone during initiation and if your ported # does not get embedded in the software properly, you are hosed.

here is how you fix it:

- from dialer, dial ##643750#
- a menu will pop up, hit edit mode
- there will be 2 options — can’t remember the names.  the top one will be what should be your phone # and the bottom one is a general access # that is *not* your phone #
- on the top entry, click edit and replace the # with your own phone #
- click the menu button on the phone and initiate the change

After I did this, my many test voicemails arrived after about 10 seconds.

Solution #3: (Quoting Sirchuck from xda-developers forum):

It sounds like there is an issue regarding your profile. You could try updating your profile.

Settings – System Updates – Update Profile

Also update the PRL while you’re there.

If those solutions don’t solve your problem, I suggest you read through the entire two forum threads. They contain other suggestions that might work.

What I Hate About the HTC Evo 4G, coming from the iPhone

Posted by Dan | Posted in HTC Evo 4G, iPhone | Posted on 08-12-2010

0

I’ve just migrated from an iPhone 3G to an HTC Evo 4G. I can’t deny that I miss my iPhone. I wanted to express my thoughts about the change and hopefully it’ll be helpful to anyone migrating. Now granted, I still like many things about the Evo, and you’ll find thousands of post that describe what’s great about Evo: 4G capability, Android, widgets, more customizations, big screen, dual camera, and because it’s not AT&T… the ability to actually make calls from NYC! What I can’t seem to find enough though, are things people dislike, especially when coming from the iPhone.

All of these refer to native apps / peripherals and how they compare to iPhone native apps. I understand that you can get replacements from the Android store.

Contacts App

  • Contacts cannot be sorted alphabetically by last name.
  • Contact Pictures get pixilated when they sync with Google.

Other Apps / Widgets

  • Calendar widget on the desktop does not show the current date like the iPhone Weather app does NOT show any cities I’m interested (like Little Neck or Lindenhurst) in other than NYC.
  • Voicemail widget does not (at least for me) show the number of new voicemails.
  • No native Notepad.
  • Tight restriction on the size you can assign to your wallpaper or contact portrait.

Phone App

  • Sometimes when people call me, it doesn’t show the portrait because the phone recognizes the incoming number as 212-… and I used 1-212-… in their contact info

General UI

  • There’s generally 2x to 4x as many button presses to get to the actions that I want. For example, trying to assign a default action to a contact. I wouldn’t mind as much, except navigation is intuitive.
  • No media manager like iTunes. As much as I despise iTunes, it lets you manage podcasts.

Actual Phone

  • Does not come with a headset / headphone. What the HELL?!?!?
  • Finding a headset / headphone with a remote control like the iPhone that lets me control the music playback, is difficult. I’ve just tried 5 different ones and none of them work.

Android Store

  • Does not except Paypal
  • Credit card is not always excepted. I’ve put two credit cards (Mastercard and Visa), and they always get rejected with no helpful error message.

Peripherals

  • Easy to get peripherals – Any electronics store has a separate section for just iPhone. Android has been around for years, but because there’s so many variations of phones, there’s a less variation.