Exmouth Means Business show: videodrome

To the show on Thusday..

Thursday 27th October 2016 0930 – 1530 at Exmouth Community College.

The event is organised by Exmouth Chamber of Commerce and thebestof Exeter and sponsored by Westerly BMW and supported by the Archant Group and Bay FM.

There are over 200 delegates coming so far where they will find a wide range of busiensses and organisations exhibiting (like ourselves), 2 speed networking sessions, 3 seminars and a networking cafe selling drinks and food throughout the day.

Come along and see ourselves and the other businesses and you might even meet some new contacts and do some business!
Tickets here: ow.ly/dRrM305t9GR

Mercifully short video here: STAR video




Jint joy: execute js from within c# #itsyourfoot

Just followed this SO answer to look at Jint on github. The project has plenty of current updates.

Imagine you have a WebAPI in C# and your client wants to select rows with a javascript filter. Well with Jint you can run arbitary code on the server. You must only use this power for good #itsyourfoot

 public void ScriptEngineShouldFilterRows()
 //Loving https://github.com/sebastienros/jint/ !
 //install-package jint then...
 var engine = new Jint.Engine()
 .SetValue("log", new Action<object>(Console.WriteLine))

//get your json of objects e.g. from select * from cats for json row
 var json = @"[{""name"":""tom""},{""name"":""fritz""},{""name"":""felix""}]";
 //decide which cats you want
 var filter = "itm.canRead = itm.name.substring(0,1)=='t';";

//write a js function filterrows that takes the rows (as a string) 
//and returns the selected rows (as a string)
 var js = @"
 function filterrows(rows) { 
 var itms = JSON.parse(rows);
 var filtered = [];
 " + filter + @"
//use the engine to call the function
 var v = engine.Execute(js)
 .Invoke("filterrows", json);
 //aagh got an exception. 
 //BUT there's a helpful error message that points you 
 //to the right row in your javascript...

//v now contains your selected rows



SQL Smalldatetime ends in 2079 (June 6th).


select CONVERT(smalldatetime,'26 Apr 2016')

select CONVERT(smalldatetime,'26 Apr 2106')

select CONVERT(datetime,'26 Apr 2106')

select convert(smalldatetime,CONVERT(datetime,'26 Apr 2106'))

See https://msdn.microsoft.com/en-GB/library/ms182418.aspx


To find which columns are affected,

select t.name, c.name from sys.columns c

inner join sys.tables t on t.object_id=c.object_id

where system_type_id=58

whoo! that’s my pension sorted out. no, wait, I’ll be dead…

SQL timeout from C# SqlCommand: check parameter direction, use SQL Trace

Unexpected SQL timeouts in a SqlCommand?

I think it was a lock conflict… i was opening (what i thought was a firehose cursor) recordset with many rows. I reduced this and the problem went away. In this case it’s a regular job so I can process 100 rows each time.

However it also helped to check parameter .Direction

writebackCmd = new System.Data.SqlClient.SqlCommand();
writebackCmd.CommandType = System.Data.CommandType.Text;
writebackCmd.CommandText = sqlWritebackCmd;
writebackCmd.Connection = sqlWritebackConnection;
writebackCmd.Parameters.Add(“@P0”, System.Data.SqlDbType.Int);//new ab_id aka rowId
writebackCmd.Parameters.Add(“@P1”, System.Data.SqlDbType.Int);//primary key
writebackCmd.Parameters[0].Direction = System.Data.ParameterDirection.Input;
writebackCmd.Parameters[1].Direction = System.Data.ParameterDirection.Input;

When I added the .Direction =  code this reduced the number of timeouts.

It was interesting to look at the sql calls using Sql Server Profiler.
For convenience set the ApplicationName to something recognisable then filter on that…

var csb = new System.Data.SqlClient.SqlConnectionStringBuilder();
csb.DataSource = …
csb.MultipleActiveResultSets = true;
csb.ApplicationName = “ChilliABLink”;

In Sql Query Analyzer, set APP=ChilliABLink

(found this here…)

From that I can see that the first call that C# makes is

declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N’@P0 int,@P1 int’,N’update [tblEvent] set [sample_sent_ab_id]=@P0 where[EventID] = @P1 and [sample_sent_ab_id] is null or [sample_sent_ab_id] @P0 ‘,@P0=213191,@P1=450661
select @p1

…after which it calls…

exec sp_execute 1,@P0=213191,@P1=450689