Short solution for short problems

AngularJS : Smart table select search not working in IE 11

I was building a web site and testing it in Chrome. Worked fine. Untill the users started testing in IE!! There the filtering in the table using dropdowns (select) didn't work. After some looking around I found out that the smarttable was binding to the input event. But IE only fires the change event with select. So the binding didn't work. The smarttable version 2.1.8 has an option to bind the search to another event:

<select st-input-event="change" st-search="Month" class="form-control">
    <option value="">All</option>
    <option ng-repeat="row in vm.filteredConsignments | unique:'Month'" value="{{row.Month}}">{{row.Month}}</option>

The st-input-event attribute allows you to change the binding. Now it can work with the change event, it still works in Chrome, but now also in IE (in my case IE11).

MSSQL: convert datetime to time

I needed to show the time between a start and end datetime in one record in the DB. This could be done using the CONVERT function:

CONVERT(char(10),  EndTime - StartTime, 114) as TotalTime

Then the result looked like this:

IIS copy files to file share in API or web site

Recently, I needed to copy some files from a database to a file share in a .Net web API that runs on an IIS. First I was trying to run the application pool using a domain user, but I couldn't get it working. The application pool keeps stopping, even if the username and password is correct and the local policies are correct.

So I found another better way to do it. In stead of giving the user permissions on the file share. I gave the server permissions on the file share. Then I ran the application pool under the NetworkService and it works.

On the file share under security, put DOMAIN\SERVERNAME and give modify rights (do not forget to include computers in de AD search). Thats it. Now the server can write to this specific location, no harm can be done. In fact, giving a user permissions can be more dangerous, because he can access it anywhere.

AngularJS and .Net WEB.API: 405 (Method Not Allowed) for PUT and DELETE

I was having some problems with put and deletes. When I ran the code on the localhost, no problem, but after installing on the servers, delete calls were giving CORS errors. I tried to figure out what was going on, but I lost some time. First I rewrote the methods to POST methods, this worked. But when a new occasion came to look for a better solution I found it here.

The thing is that DELETE and PUT are sending a OPTION request first to the API on the server. If this method is not there, then it will not work. The error message will not really point you into the right direction. 

But instead of adding the OPTION methods foreach DELETE or PUT you could also disable WebDAV in IIS. That really does the trick. No code changes needed, just a simple configuration.

  <modules runAllManagedModulesForAllRequests="true">
    <remove name="WebDAVModule"/>
    <remove name="WebDAV" />

And thatis it.

No more of these now:

Message count in MSQUEUE

An easy powershell comment can help to get more info about a messagequeue.

This get more info on all the queue's you have defined:

# Get all message queues

The next command gives youa table overview of all queue's and their item count:

# Get all the private message queues.
# Display only the QueueName and MessageCount for each queue.
Get-MsmqQueue -QueueType Private | Format-Table -Property QueueName,MessageCount;

Source Link

You could off also take a look in the queue browser:

EF: Oracle.ManagedDataAccess Specified Cast is not valid on decimal

Error: Specified cast is not valid. 

CorrId: GetClientAcceptances 

Stack: at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i) 

at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)

Got this error while working with EF 6 and Oracle DB. Using the Oracle.ManagedDataAccess package. (Version about packages below)

The reason was that in Oracle the number type was set on a column and no precision specified. We had some old data that had some values with a very large precision, and when EF tries to map it to a decimal, there was a specified cast exception. So I rounded all the records in the DB to precision 2, because that was enough for this application and the problem was solved. Some helper query for this:

select RISKFACTOR from MYTABLE where RISKFACTOR - trunc(RISKFACTOR,3) <> 0;

  <package id="Oracle.ManagedDataAccess" version="12.1.24160719" targetFramework="net461" />

  <package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.2400" targetFramework="net461" />

Passing objects in methods by ref or not....

public void Foo(Image image)
    // This change won't be seen by the caller: it's changing the value
    // of the parameter.
    image = Image.FromStream(...);

public void Foo(ref Image image)
    // This change *will* be seen by the caller: it's changing the value
    // of the parameter, but we're using pass by reference
    image = Image.FromStream(...);

public void Foo(Image image)
    // This change *will* be seen by the caller: it's changing the data
    // within the object that the parameter value refers to.
Source: Stackoverflow