Can I Debug It?

Categories: Uncategorized

Final “Catch”

September 16, 2014 Leave a comment

I have been debating the implementations of try catch everywhere or just where I know it might come up. Like when calling an “outside” service. Leaning that way, I’m getting more specific but this page isn’t so wonderful:

An error occurred while processing your request.

So, two things have happened. First, since I was on a fast forward on C# MVC.NET and self taught all the way I didn’t have a catchall. I know that is no excuse, but it brought value to yesterday. I always say, “a day not learned is a day wasted.” So I’m going back to all my MVC applications and adding this block of code to my Global.asax.cs:

protected void Application_Error()
{
Exception unhandledException = Server.GetLastError();
HttpException httpException = unhandledException as HttpException;
Log.Add(“Unhandled”, “Global.asax.cs error caught”, unhandledException, true);
if (httpException == null)
{
Exception innerException = unhandledException.InnerException;
httpException = innerException as HttpException;
}

if (httpException != null)
{
int httpCode = httpException.GetHttpCode();
switch (httpCode)
{
case (int)System.Net.HttpStatusCode.Unauthorized:
Response.Redirect(“/Http/Error401”);
break;
}
}
}

You may notice the log on the third line. It drives notices to my log service. This is external from any of my clients but it allows me to be proactive and have detailed error messages in my logger to know what really happened. I also have implemented logging levels that are set in the web.config so I can easily change that without recompiling/deploying the application. Stay tuned for application logging.

Categories: Uncategorized

See ‘EntityValidationErrors’

So I receive this error all the time but it’s contents are “hidden”.

Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details.

Here’s what I put in in order to see what is really going on inside.

///

/// Wrapper for SaveChanges adding the Validation Messages to the generated exception
///

/// The context.
private void SaveChanges(DbContext context)
{
try
{
context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
StringBuilder sb = new StringBuilder();

foreach (var failure in ex.EntityValidationErrors)
{
sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
foreach (var error in failure.ValidationErrors)
{
sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
sb.AppendLine();
}
}

throw new DbEntityValidationException(
"Entity Validation Failed - errors follow:\n" +
sb.ToString(), ex
); // Add the original exception as the innerException
}
}

Categories: Uncategorized

MVC4 Autovalidation

April 11, 2014 Leave a comment

I love it to the max: The way MVC4 client side validation takes care of itself I may forget how to write javascript all together. . . Just kidding. Well anyway, The trouble today was when entering a decimal and getting thus far : “34.” That is not considered a number but the eager validation flashes up saying it isn’t then promptly disappears once the next digit is entered.

I knew the problem had to do with key-something creating the “eager validation” I referred to above. I wanted an approach with as little hacking into validation as possible and found this little script that gave me success:

    $(function () {
        var settngs = $.data($('form')[0], 'validator').settings;
        settngs.onkeyup = false;
    });


If i want to go a step further, I can make validation wait until form submission with this:

    $(function () {
        var settngs = $.data($('form')[0], 'validator').settings;
        settngs.onkeyup = false;
        settngs.onfocusout = false;
    });


BTW: settngs is not a typo!! It’s just to show the difference.

Hope it helps.

EvoD

PHP & .NET Fiddle

March 18, 2014 Leave a comment

Hey, phpfiddle.org is running like poo so i found this one: http://sandbox.onlinephpfunctions.com/
I also found this for .NET: https://dotnetfiddle.net/

Categories: PHP, Web Tech

Unlinked DB User in MSSQL

I always have an issue with an orphaned user in a DB after changes or restores or our “fancy” data authentication model. Here’s how to relink them up:

ALTER USER OrphanUser WITH LOGIN = correctedLoginName

StackOverflow

Categories: DataBases, MSSQL

Ole Automation Procedures setup and configuration

June 19, 2013 Leave a comment

USE master
GO
GRANT EXECUTE ON [sys].[sp_OADestroy] TO [user]
GO
GRANT EXECUTE ON [sys].[sp_OACreate] TO [user]
GO
GRANT EXECUTE ON [sys].[sp_OAMethod] TO [user]
GO
GRANT EXECUTE ON [sys].[sp_OASetProperty] TO [user]
GO
GRANT EXECUTE ON [sys].[sp_OAGetErrorInfo] TO [user]
GO

EXEC

sp_configure ‘show advanced options’, 1
GO
— To update the currently configured value for advanced options.
RECONFIGURE
GO

— To enable the feature.
EXEC
sp_configure ‘Ole Automation Procedures’, 1
GO

— To update the currently configured value for this feature.
RECONFIGURE
GO

Categories: Uncategorized

Implement Program Flow (25%) Part 3

February 23, 2013 1 comment

Implement exception handling.

This objective may include but is not limited to: set and respond to error codes; throw an exception; request for null checks; implement try-catch-finally blocks.

  • jsFiddle of a try catch example that uses a throw. I noticed that the throw sends a string rather than an error object. Actually it sends whatever you send it: string, object, number, etc.

On a related topic, here’s a good method to check connections in C# and not use exceptions: http://msdn.microsoft.com/en-us/library/seyhszts(v=vs.100).aspx

Fiddle Fiddle Fiddle

February 22, 2013 Leave a comment

Found this new fiddle today: http://sqlfiddle.com/#!3/88cd4/2.
That is just as fine a toy as this http://jsfiddle.net/

Categories: DataBases, JavaScript, MSSQL, MySQL

Implement and Manipulate Document Structures and Objects (24%) Part 1

February 20, 2013 1 comment

Create the document structure.

This objective may include but is not limited to: structure the UI by using semantic markup, including for search engines and screen readers (Section, Article, Nav, Header, Footer, and Aside); create a layout container in HTML:

  • jsFiddle of styleless HTML5 semantic tags listed
  • jsFiddle with added layout and color styles