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
Follow

Get every new post delivered to your Inbox.