QueryFailedError: Error: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received type number (0) TypeORM

Viewed 156

I am using typeorm to store data to an mssql database but Im having this error

QueryFailedError: Error: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received type number (0)

I don't understand what it means or which part of my code is causing the problem. I didn't have this error when I was using mysql database, but now I have to move it to mssql. Can someone please help.

Entity code:

import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;

    @Column()
    lastName: string;

    @Column()
    age: number;

}

Connection Manager Code

const connectionManager = new ConnectionManager();
const connection = connectionManager.create({
  type: "mssql",
  host: "localhost",
  port: 1433,
  username: 'sa',
  password: 'Str0ngp@ssw0rd',
  database: "sampledb",
  entities: ["dist/entity/*"],
  logging: false,
  synchronize: true,
  extra: {
    trustServerCertificate: true,
 }
});

Adding data code snippet

const conn = await connect();
const userrepository = conn.getRepository(User);
const user = new User();
user.firstName = "Timber";
user.lastName = "Saw";
user.age = 25;
const response = await userrepository.save(user);
0 Answers
Related