Monday, September 30, 2013

.Net: Unknown column 'GroupBy1.K1' in 'field list'

I was having the error

Unknown column 'GroupBy1.K1' in 'field list'

The query was:

                    var results =
                        from cs in skydeskDB.Cases
                        where
                        cs.AgentId == AgentId
                        && cs.ClosedAt >= iniDate
                        && cs.ClosedAt < endDate
                        group cs by cs.ClosedAt.Value.Hour into g
                        select new
                        {
                            closedcasecounter = g.Count(),
                            daynumber = g.Key
                        };

After spending a lot of time on internet I found a post that suggested that the problem was a mysql connector  bug so I updated it from 6.6.5 to 6.7.4. But the problem continued so I had to group the data using a for loop :(

If you find any solution, please let me know in the comments section.

Resources:
http://bugs.mysql.com/bug.php?id=46742

Log4J: Simple File configuration example


## HelloWorld class
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class HelloWorld {

static final Logger logger = Logger.getLogger(HelloWorld.class);

public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
logger.debug("Sample debug message");
logger.info("Sample info message");
logger.warn("Sample warn message");
logger.error("Sample error message");
logger.fatal("Sample fatal message");
}
}

## log4j.properties file
log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.FileAppender ## file apenfder configuration
log4j.appender.CA.File=main.log ## log file name
log4j.appender.CA.layout=org.apache.log4j.PatternLayout

log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 

Referecnes:
http://www.dzone.com/tutorials/java/log4j/log4j-configuration.html
http://www.dzone.com/tutorials/java/log4j/log4j-file-appender-example-1.html

Tuesday, September 24, 2013

MySQL: stored procedures tutorial

Here is the link of a nice ans simple MySQL stored procedures tutorial:

http://www.mysqltutorial.org/stored-procedures-parameters.aspx

C#: get date time given current date and day of week

        /// <summary>
        /// Returns the daytime of the day of the week that the specified date is in. 
        /// </summary>
        public static DateTime GetDayOfWeek(DateTime dayInWeek, DayOfWeek dayOfWeek)
        {            
            DateTime lastDayInWeek = dayInWeek.Date;
            int increment = 1;
            if (dayOfWeek < dayInWeek.DayOfWeek) {
                increment = -1;
            }

            while (lastDayInWeek.DayOfWeek != dayOfWeek)
            {
                lastDayInWeek = lastDayInWeek.AddDays(increment);                                
            }                
            return lastDayInWeek;
        }

implementation samples:

get the first day of the week:
DayOfWeek dayOfWeekPriority = DayOfWeek.Monday;
DateTime iniDatePriority = DateTime.Now;
DateTime endDatePriority =GetDayOfWeek(iniDatePriority, dayOfWeekPriority).AddDays(1);

get the last day of the week:
DayOfWeek dayOfWeekPriority = DayOfWeek.Friday;
DateTime iniDatePriority = DateTime.Now;
DateTime endDatePriority = DashboardManager.GetDayOfWeek(iniDatePriority, dayOfWeekPriority).AddDays(1);

Resource:
http://joelabrahamsson.com/getting-the-first-day-in-a-week-with-c/

Dot Net: translate error

There is a useful page that heps you find the translation of .NET, Windows and Microsoft SQL Server error messages error from many languages to english:

http://finderr.net/

LINQ: LINQ to Entities no reconoce el método y este método no se puede traducir en una expresión de almacén

I was getting the error:

"LINQ to Entities no reconoce el método 'System.DateTime AddHours(Double)'
del método, y este método no se puede traducir en una expresión de almacén."

the code was:
   var results =
       from c in skydeskDB.Cases
       join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
      where
         c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
         && cs.Name != "closed"
         && c.EstimatedDate <= DateTime.Now
         && c.EstimatedDate >= DateTime.Now.AddHours(-1.0) // here was the problem
      group cs by cs.Name into g
      select new
      {
         type = "toexpire",
         statuscounter = g.Count(), 
         statusname = g.Key
       };

The solution was defining the DateTime.Now.AddHours(-1.0) outside the query:

       var estimatedDate = DateTime.Now.AddHours(-1); // here,  outside the query
       var results =
                           from c in skydeskDB.Cases
                            join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
                            where
                                c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
                                && cs.Name != "closed"
                                && c.EstimatedDate <= DateTime.Now
                                && c.EstimatedDate >= estimatedDate // here is already calculated
                            group cs by cs.Name into g
                            select new
                            {
                                type = "toexpire",
                                statuscounter = g.Count(), 
                                statusname = g.Key
                            };



Friday, September 20, 2013

MySQL: Get total values from a column

At first I had:

SELECT
COUNT(casestates.id) AS statustotal
, casestates.name AS statusname
FROM
cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
AND casestates.name != 'closed'
GROUP BY
casestates.name

The return was:

-----------------------------------------
| statustotal    | statusname |
-----------------------------------------
|       5           |      New     |
-----------------------------------------
|       18         |      Open    |
-----------------------------------------
|       14         |      Solved  |
-----------------------------------------

Know using Use the ROLLUP and IFNULL clauses:

SELECT
 COUNT(casestates.id) AS statustotal
 ,IFNULL(casestates.name,"Total") AS statusname -- changed here
FROM
 cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
 cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
 AND casestates.name != 'closed'
GROUP BY
 casestates.name
WITH ROLLUP; -- changed here

The return is:

statustotal statusname
-----------------------------------------
| statustotal    | statusname |
-----------------------------------------
|       5           |      New     |
-----------------------------------------
|       18         |      Open    |
-----------------------------------------
|       14         |      Solved  |
-----------------------------------------
|       37         |      Total     |
-----------------------------------------

Resources:

Tuesday, September 10, 2013

Visual Studio 2012: "Analyze Solution for Code Clones" option

Here is an interesting article about Visual Studio 2012  "Analyze Solution for Code Clones" option:

http://blogs.msdn.com/b/jasonsingh/archive/2013/03/21/problems-with-copy-pasting-code.aspx

Visual SVN Server: Visual SVN Server service failed to start:

I was getting:

Visual SVN Server: Visual SVN Server service failed to start: El servicio ha devuelto un error especifico del servicio. (0x8007042a).

Please check VisualSVN Server log in Event Viewer for more details.

So, I checked the Event Viewer and It said:

make_sock: could not bind to address 0.0.0.0:443 (OS 10048) Solo se permite un uso de cada dirección de socket (protocolo/dirección de red/puerto)

The error was that Skype had already initiated and was using the port 443. Skype by default try to use ports 80 or 443. So I killed the skype process and tryed to start Visual SVN Server and everything worked fine.

Then, when you try to start skype, it uses another port and starts correctly.

Resources:


Monday, September 9, 2013

jQuery: jquery-1.10.2.min.map is triggering a 404 (Not Found)

"A source map it's a way to map a combined/minified file back to an unbuilt state. When you build for production, along with minifying and combining your JavaScript files, you generate a source map which holds information about your original files. When you query a certain line and column number in your generated JavaScript you can do a lookup in the source map which returns the original location"

So,you have some options:
1. Stop using the .min.js file and use the .js file (recomended for development environmens)
2. Downlad the .map file and add it to your libs: http://jquery.com/download/ Select the option: "Download the map file for jQuery x.xx.x"
3. Delete, from your .min.js file, the  line:
//@ sourceMappingURL=jquery-1.10.2.min.map 

References:
http://stackoverflow.com/questions/18365315/jquerys-jquery-1-10-2-min-map-is-triggering-a-404-not-found
http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

backboneJs: "change:[attribute]" event is not firing

add default values  to the model :

var testModel = Backbone.Model.extend({
defaults: {
    "attribute":  ""
  }
});