Are the posted questions getting worse?

  • Sean Lange wrote:

    x wrote:

    I just tried something similar and it seems that the outer catch wouldn't catch anything that the inner catch eats. I could be wrong, I just couldn't duplicate the outer catch catching the inner exception, course just using divide by 0 as the error. I seem to think it would have to be rethrown(????). I do get a nag about an unused variable (the exception). Obviously could be me %-)

    That is really my point. What is the point of all those inner catches when the outer catch just swallows any exception. Removing all of the inner ones would result in the same result (a useless result) with a lot less code.

    My point was that the inner catch did the eating if the error was in the inner try, not the outter, unless I'm not getting the same situation coded. Based on my test (if not in error), the outter catch will only eat, if the outter try is the one with the error, so the inner try never runs any statements at all. Sure, if the workload in its entirety is a transaction that rolls back then its moot no matter what, but oftentimes theres some local bit twiddling going on.

    If the outter catches, then NO code in the inner try runs, erroneous or not.

     

     

  • x wrote:

    So is the class JsonResourceResultsHandler your own class(?) or part of the api? Couldn't google it %^)

    It's part of a C# library called JsonAutoService I developed originally to help migrate a couple of .NET full framework API's to .NET Core.  The full framework API's I'm responsible for have/had (migration is in progress) lots of methods which use ADO.NET to call stored procedures.  Instead of continually updating and maintaining all that code (which basically are just type conversions) this library replaces it with nothing by just using Json as the messaging medium.  The plan is to open source the library and make it available via Nuget.org.  I'm having to figure out what all of that entails tho.  It's going to require a lot of documenting and explaining.  Maybe Youtube videos.

    Here's the implementation of JsonResourceResultsHandler.  The injected service class JsonAutoService contains a set of methods to execute sql statements, to return outputs to SqlTypes in C#, and to handle logging errors and exceptions.

    using JsonAutoService.Service;
    using JsonAutoService.Structures;
    using Microsoft.AspNetCore.Mvc.Filters;
    using Microsoft.Extensions.Options;
    using Newtonsoft.Json;
    using System;
    using System.IO;
    using System.Threading.Tasks;

    namespace JsonAutoService.ResourceHandlers
    {
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
    public class JsonResourceResultsHandler : Attribute, IAsyncResourceFilter
    {
    private readonly JsonAutoServiceOptions _options;
    private readonly IJsonAutoService _jsonAutoService;
    private readonly string procName;

    public JsonResourceResultsHandler(IOptionsMonitor<JsonAutoServiceOptions> options, IJsonAutoService jsonAutoService, object procName)
    {
    this._options = options.CurrentValue;
    this._jsonAutoService = jsonAutoService;
    this.procName = procName.ToString();
    }

    public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
    {
    var httpContext = context.HttpContext;
    var request = httpContext.Request;
    var user = httpContext.User;

    //Serialize Routes
    var jsonRoutes = JsonConvert.SerializeObject(context.RouteData.Values);

    //Serialize Headers
    var headerDictionary = _jsonAutoService.GetHeadersDictionary(request.Headers, user);
    var jsonHeaders = JsonConvert.SerializeObject(headerDictionary);

    //Get connection string
    var sqlConnection = httpContext.Items[_options.ConnectionStringName].ToString();

    //Handle request
    using (var reader = new StreamReader(request.Body))
    {
    var body = await reader.ReadToEndAsync();

    switch (request.Method)
    {
    case nameof(SupportedMethods.GET):
    var getResponse = await _jsonAutoService.SqlGetAsync(sqlConnection, jsonHeaders, procName, jsonRoutes);
    context.Result = _jsonAutoService.JsonGetContentResult(getResponse.ToString());
    break;
    case nameof(SupportedMethods.PUT):
    var putResponse = await _jsonAutoService.SqlPutAsync(sqlConnection, jsonHeaders, procName, jsonRoutes, body);
    context.Result = _jsonAutoService.JsonPutContentResult(putResponse, _options.Mode, _options.ErrorThreshold);
    break;
    case nameof(SupportedMethods.POST):
    var postResponse = await _jsonAutoService.SqlPostAsync(sqlConnection, jsonHeaders, procName, jsonRoutes, body);
    context.Result = _jsonAutoService.JsonPostContentResult(postResponse, _options.Mode, _options.ErrorThreshold);
    break;
    case nameof(SupportedMethods.DELETE):
    var deleteResponse = await _jsonAutoService.SqlDeleteAsync(sqlConnection, jsonHeaders, procName, jsonRoutes);
    context.Result = _jsonAutoService.JsonDeleteContentResult(deleteResponse, _options.Mode, _options.ErrorThreshold);
    break;
    case nameof(SupportedMethods.HEAD):
    var headResponse = await _jsonAutoService.SqlHeadAsync(sqlConnection, jsonHeaders, procName, jsonRoutes);
    context.Result = _jsonAutoService.JsonHeadContentResult((bool)headResponse);
    break;
    default:
    context.Result = _jsonAutoService.JsonDefaultContentResult();
    break;
    }
    }
    }
    }
    }

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • x wrote:

    My point was that the inner catch did the eating if the error was in the inner try, not the outter, unless I'm not getting the same situation coded. Based on my test (if not in error), the outter catch will only eat, if the outter try is the one with the error, so the inner try never runs any statements at all. Sure, if the workload in its entirety is a transaction that rolls back then its moot no matter what, but oftentimes theres some local bit twiddling going on.

    If the outter catches, then NO code in the inner try runs, erroneous or not.

    But ALL of the catch blocks are empty. So why bother with writing all the inner empty catches at all? Any exception thrown there would be caught and swallowed by the outer empty catch. Their code does not have any transaction logic and it all just blindly assumes that the code before it worked as expected. I could see an argument that you want the rest of the code to continue working. But for that to make any sense at all there should be something in the catch blocks so somebody knows that something went wrong.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange wrote:

    x wrote:

    My point was that the inner catch did the eating if the error was in the inner try, not the outter, unless I'm not getting the same situation coded. Based on my test (if not in error), the outter catch will only eat, if the outter try is the one with the error, so the inner try never runs any statements at all. Sure, if the workload in its entirety is a transaction that rolls back then its moot no matter what, but oftentimes theres some local bit twiddling going on.

    If the outter catches, then NO code in the inner try runs, erroneous or not.

    But ALL of the catch blocks are empty. So why bother with writing all the inner empty catches at all? Any exception thrown there would be caught and swallowed by the outer empty catch. Their code does not have any transaction logic and it all just blindly assumes that the code before it worked as expected. I could see an argument that you want the rest of the code to continue working. But for that to make any sense at all there should be something in the catch blocks so somebody knows that something went wrong.

    I gotcha! In the little test I tried, I could see which block ran, and could see that the outter catch did not actually catch anything, so I just couldn't duplicate "Any exception thrown there would be caught and swallowed by the outer empty catch", because in my case it was swallowed by the catch that matched the erroring try, and the outter catch didn't catch anything. Its probably not an important distinction in any case except for pendants like me 🙂

     

     

     

  • x wrote:

    I gotcha! In the little test I tried, I could see which block ran, and could see that the outter catch did not actually catch anything, so I just couldn't duplicate "Any exception thrown there would be caught and swallowed by the outer empty catch", because in my case it was swallowed by the catch that matched the erroring try, and the outter catch didn't catch anything. Its probably not an important distinction in any case except for pendants like me 🙂

    It is an important distinction as there could be reason to use an inner catch. But in this example it was just nested for the sake of being nested. So much effort for no result. 😉

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • scdecade interesting stuff! If / when you get a public project going you should drop us a note!

     

  • regarding the SSDT mess, I had studio 15 installed so I could follow one of our developers efforts, but then I went and installed a local SQL 16 and plus had ssms 19. So then when I went to install the data tools for SSIS, some CLR-sounding gadget was too recent. So idiot me went and installed studio 19 with the assumption that then SSIS would work only to run into difficulties even finding it in whatever passes for the "extensions" mess they now talk about.

     

  • x wrote:

    scdecade interesting stuff! If / when you get a public project going you should drop us a note!

    Thanks!  Yes I'm going to hopefully come up with a plan.  At this point I'm kind of not knowing what steps to take.  We'll see I guess

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Chris Harshman wrote:

    The Update Failed message reminds me of when I was a database developer some time ago working with Oracle, and the DBA's there programmed some automated job that would e-mail me with the message:

    "Error: Job completed successfully."

    ...so was it supposed to fail but it didn't?

    That reminds me of  a developer that I worked with, who once said:

    "It works, but I know why".

  • BrainDonor wrote:

    Chris Harshman wrote:

    The Update Failed message reminds me of when I was a database developer some time ago working with Oracle, and the DBA's there programmed some automated job that would e-mail me with the message:

    "Error: Job completed successfully."

    ...so was it supposed to fail but it didn't?

    That reminds me of  a developer that I worked with, who once said:

    "It works, but I know why".

    Ba dum dum! Ching!

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Eirikur Eiriksson, sorry to hear about your crystall ball. I hope it cristallizes again. Perhaps with the hourglass bbq of Steve.

  • Jo Pattyn wrote:

    Eirikur Eiriksson, sorry to hear about your crystall ball. I hope it cristallizes again. Perhaps with the hourglass bbq of Steve.

    This is how it looks like, kind of like it though...

    😎

     

  • Eirikur Eiriksson wrote:

    Jo Pattyn wrote:

    Eirikur Eiriksson, sorry to hear about your crystall ball. I hope it cristallizes again. Perhaps with the hourglass bbq of Steve.

    This is how it looks like, kind of like it though...

     

    I should sue for patent infringement... that's what my morning constitutional looks like.  If I swallow a handful of toothpicks the night before, they come out complete with the 3 legged varnished stands. 😀 😀 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 2019 is finally out for general release: SQL Server 2019 is now generally available

    Time to start looking at the specs and what it really includes in the Standard Licences, as I got the green light on replacing our 2012 server last month. Be nice to finally get access to some of the more recent tools (though I'm not excited for the new Cardinality Estimator).

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A wrote:

    2019 is finally out for general release: SQL Server 2019 is now generally available

    Time to start looking at the specs and what it really includes in the Standard Licences, as I got the green light on replacing our 2012 server last month. Be nice to finally get access to some of the more recent tools (though I'm not excited for the new Cardinality Estimator).

    Trying to decide if it might be worth it to step us down from Enterprise to Standard edition.  The main reason we're on EE is we're required to use TDE and if that's going to be available in Std, well...

    The 4 core limit isn't really a big deal for us, none of my servers (currently) have more than that, the 128GB of RAM also isn't a big deal as my largest is 32GB.

    So being able to cut the licensing costs in half, well, that'd be a nice feather in the cap.

Viewing 15 posts - 64,126 through 64,140 (of 66,815 total)

You must be logged in to reply to this topic. Login to reply