Posts

Showing posts from August, 2017

ADO.Net Async with Transactions... A Lesson Learned

Image
Last night I was testing out a new WebApi Filter I've added to a project, its fairly simple, log some data that comes from a HTTP header to the DB. This particular project has no Entity Framework or anything, just simple ADO.Net, in fact I think the project has 3 stored proc's in total. I tend to Async all the things by default so when I originally wrote my DB code I had: using (var conn = new SqlConnection(_connectionString)) {      await conn.OpenAsync();      using (var transaction = conn.BeginTransaction())      {           var command = conn.CreateCommand();           command.CommandText = "[Api].[LogDeviceRequest]";           command.CommandType = System.Data.CommandType.StoredProcedure;           command.Transaction = transaction;           command.Parameters.AddWithValue(//etc             try           {              await command.ExecuteNonQueryAsync();           }           catch           {              transaction.Rollback();    

Playing further with ASP.Net Core whilst on my hols... VSCode fun and cool new Anti Forgery Validation

I'm on vacation, 10 days in Norfolk with extremely limited connectivity and action packed days with the kids. Whilst here on two nights everyone has fallen asleep before me so I decided it would be a good time to poke around further at ASP.Net Core as I've still not produced any production code with it yet, only small samples. Now I don't have my laptop on me but I do an old one that's here purely for any work emergencies and for childcare emergencies, (you know the ones, its 6am and the 2 year old is awake, peppa pig at 6am is an emergency!). This means I have literally nothing on me and I can only tether internet via my wife's iPhone 6 which has barely a bar of signal, this rules out a cloud VM running VS. So I turned to VSCode, its sooo lightweight its easy to download, install and run on this laptop. Get the .Net Core 2.0 SDK and the VSCode C# extension and you are literally running within 30 mins. I won't go to much into the projects setup and stuff as

Code therapy brought to you this week by .Net Core 2

Image
So the last week has been hard going so tonight I decided to have some code therapy. I've been meaning to explore .Net Core 2 further and decided tonight was the time to port a library I had written in Mono for Raspbian over to .Net Core land. It's worth noting that .Net Core 2 is only in preview on Raspbian but thats good enough for me ;) Getting Started First things first I updated VS2017 to the latest update 3 release. My Visual Studio wasn't telling me the update was available so I simply got the web installer again from VisualStudio.com and it advised VS was already installed and could be updated. This took about 35 mins on my Dell XPS 13 laptop but on my SurfacePro 3 its taken nearly an hour. .Net Standard Choices I then chose to create a new .Net Standard project but found I couldn't target .Net Standard 2. Turns out Update 3 doesn't include .Net Core 2 you need to go get this from: https://www.microsoft.com/net/core#windowscmd You can now c