Am using mysql within my angular2-meteor app , am trying to conclude a full transaction including opening , inserting … and closing my database.
i’m confronting a problem of a closed socket which causes a full crash of my app when i’m closing it , here is my code and the error ,
if there is any propositions ???
- My code :*
- Main.ts
import {loaduser} from “./load-users”;
if(Meteor.isServer){
Meteor.onConnection(loaduser)
}
2) My function :(load-users.ts)
var Users: Mysql.Collection;
var db : Mysql.MeteorDatabase;
export function loaduser() {
if(!db) {
connexion();
}
traitement();
db.end(function(err){ //the error is here });
function connexion() {
var connectionSettings = {
host: ‘localhost’,
user: ‘root’,
port: 3300,
password: ‘’,
database: ‘my_db’
};
db = Mysql.connect(connectionSettings);
}
function traitement (){
Users = db.meteorCollection<Object>("users", "usersCollection");
console.log("condition " + Users.find().count());
}
};
3) The error :
W20160413-16:37:48.281(2)? (STDERR) throw err; W20160413-16:37:48.281(2)? (STDERR) ^ W20160413-16:37:48.281(2)? (STDERR) Error: This socket is closed. W20160413-16:37:48.281(2)? (STDERR) at Socket._write (net.js:638:19)
ANy ideas ?