MTA Email alert throws DBNull exceptions on legacy accounts

Whoops!  Upgrades are hard. 

My MTA Long Island Railroad Email alert was upgraded, but the upgraded account cannot change anything. Well, at least, yet.

When attempting to Save the changes, the VB.NET stuff throws a DBNull cannot be compared to the string "Y" error.


Here's my submission to there customer server web page:

Dear Sir or Madam,


I cannot change my account information.

I logged in using the information provided by the email entitled
"Your Sign In Information" of 
Tue, 25 Nov 2008 07:24:28 -0800 (PST)

Sadly, while seeming to provide wonderful capabilities, my changes are refused because of a DBNull database value :-(

Your transition web site for the new "Email Alert" has a problem in the Visual Basic scripting. The problem is that the value returned for my record (and I am assuming many other customer records) is a "NULL". The testing of the null value against a string value, "Y" cause the VB based web page to throw an exception.

Good pages to help resolve this problem are:

From Microsoft's Developer Network site:

How to Handle Null and DBNull

Conversion from type 'DBNull' to type 'String' is not valid

.NET Framework Class Library
DBNull Class 
(See Examples section)

Here's the exception text for my account when I attempted to "Save" any changes from the page

Server Error in '/' Application.
Operator '=' is not defined for type 'DBNull' and string "Y". 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Operator '=' is not defined for type 'DBNull' and string "Y".

Source Error: 

Line 55: cmd.ExecuteScalar()
Line 56: Conn1.Close()
Line 57: If outparm.Value = "Y" Then
Line 58: Return True
Line 59: Else

Source File: C:\Inetpub\wwwroot\NYMTA-FINAL\Customer_Modal.aspx.vb Line: 57 

Stack Trace: 

[InvalidCastException: Operator '=' is not defined for type 'DBNull' and string "Y".]
  Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(Object Left, Object Right, Boolean TextCompare) +514383
  Customer_Modal.IsEmailOrSMSAutorized(String emailOrSMS) in C:\Inetpub\wwwroot\NYMTA-FINAL\Customer_Modal.aspx.vb:57
  Customer_Modal.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\NYMTA-FINAL\Customer_Modal.aspx.vb:30
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +50
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

Hope this helps,
Prof. Chris Lent


Chris Lent

  Your e-mail has been sent
The reference number for your e-mail is \'081126-000621\'

Thank you for your inquiry.