Wasn't maybe the fact i did not open connection in function? ':D