Encountered an issue with the node-mssql error message while attempting a bulk insert: "A premature end-of-message was encountered while reading the current row from the host."

While attempting to utilize the .bulk operation within the node-mssql library in node.js, an error message is being returned:

While reading current row from host, a premature end-of-message was encountered--an incoming data stream was interrupted when the server expected to see more data. The host program may have terminated. Ensure that you are using a supported client application programming interface (API)
// the issue arises when calling this function
export async function insert(
  transaction: sql.Request,
  data: any[],
) {
  const table = prepare(data);
  return await transaction.bulk(table);
}

function prepare(data: any[]) {
  const table = new sql.Table('dbo.SomeTable');
  table.create = false;
  table.columns.add('MyColumn1', sql.Int, { nullable: false });
  table.columns.add('MyColumn2', sql.Int, { nullable: false });
  table.columns.add('MyColumn3', sql.Int, { nullable: false });

  for (const mov of data) {
    table.rows.add(
      mov.field1,
      mov.field2,
      mov.field3
    );
  }
  return table;
}

Answer №1

After spending some time troubleshooting, I finally found the root cause of the issue - my data array was actually empty. The solution that helped me can be found at this URL: https://github.com/tediousjs/tedious/issues/212#issuecomment-628330044

I have encountered similar errors in the past as well. It often occurs when no rows are inserted within a loop due to an empty array. This situation typically arises when columns are added and an array from another source is used for row insertion. To prevent such errors, it's advisable to check if the array is empty before executing the bulkload operation. (shared by user jianingliu on Github)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passing properties from a parent component to a child component in a React TypeScript application

I'm currently facing an issue with passing props to my component. It seems like I am unable to pass the 'Commune' due to it having a name property. Does anyone have any suggestions on how I can pass Commune.name as a prop to my component? ...

Innovative approaches to enhancing Feathers services through the use of relational data in design patterns

I'm in the process of developing a straightforward application that involves a one-to-many relationship between data entities. Specifically, I am working with feathers js and sequelize (utilizing sqlite) to create a system where each site can have mul ...

What strategies are most effective for managing prop function arguments in React with TypeScript?

Imagine having the following scenario: type Props = { onClose: () => void } const MyComponent = ({ onClose }: Props) => { // my component } However, there is a possibility that onClose could accept any function with potentially different argumen ...

What is the best way to determine Prisma types across various projects?

My current project has the following structure: dashboard -- prisma-project-1 -- prisma-project-2 -- client-of-prisma-project-1-and-prisma-project-2 This dashboard is designed to merge data from two separate databases and display them in a meaningful w ...

Typescript and Visual Studio Code Issue: Module "myimage.png" Not Found

I am encountering an issue where VS Code is complaining about not being able to find a module when trying to import an image from an assets directory within my project. Despite the fact that the image import works fine, I keep receiving the error message: ...

difficulty with closing nested Mat-dialogBoxes

I am facing an issue with passing data between multiple dialog boxes in my parent raster component. I have a parent raster component that opens the first dialog box, followed by a second dialog box. My goal is to pass data from the last dialog box back to ...

The resolver function in the Nextjs higher order API is not defined

I am trying to create a custom wrapper function for my NextJs API routes that will verify a JWT in the request, validate it, and then execute the original API handler. Here is how I have defined my wrapper function: interface ApiError { message: string, ...

Encountering a Typescript error while attempting to convert a JavaScript file to Typescript within an Express

After deciding to transition my express.js code to typescript, I have encountered an issue with my user model. Below is a simplified version of the code: //user.model.ts import { Schema, Types } from 'mongoose'; export interface User { na ...

How to safely add multiple objects to an array in TypeScript & React without replacing existing objects - Creating a Favorites list

I'm in the final stages of developing a weather application using TypeScipt and React. The last feature I need to implement is the ability for users to add queried locations to a favorites list, accessed through the "favorites" page. By clicking on a ...

Error: XYZ has already been declared in a higher scope in Typescript setInterval

I've come across an interesting issue where I'm creating a handler function and trying to set the current ref to the state's value plus 1: const useTimer = () => { const [seconds, setSeconds] = useState(0); const counterRef = useRef(n ...

Having trouble with the dropdown button functionality when looping through it in Angular

Currently, I am working with Angular and have implemented a tree-based structure. Within this tree structure, there is a dropdown button labeled "Dropdown." The issue at hand is that when I click on the "Dropdown" button, the dropdown functionality does ...

Creating both Uniform and Varying drawings on a single webGL canvas

My goal is to create this specific illustration. https://i.sstatic.net/5AfdW.png This project requires the usage of TypeScript. The Code: The code is organized across multiple files. Within the scenegraph file, there's a function that visits a gro ...

Frequently found items in TypeScript

I need help incorporating a global object in TypeScript for my application. Specifically, I want to have user details available and bindable throughout the entire application after a remote call. Can someone provide an example of how this can be achieved? ...

What is the proper way to specify the interface as Dispatch<Action>?

My goal is to create an interface with the dispatch function without using Redux. interface DispatchProps { dispatch: (action: { type: string }) => void; } export function addTwoToNumber({ dispatch }: DispatchProps) { dispatch({ type: '@addTwo ...

Exploring the functionality of angular reactive forms in creating intricate JSON structures

After numerous attempts to resolve the issue on my own, I am reaching out to an Angular developer for assistance. My goal is to display a JSON object in the UI: Here is the JSON Object : items={"departure":"New York","arrival":"California","stations":[ ...

Create a system for detecting changes in simple input elements and triggering a function to update the final result

There are a maximum of 12 inputs that represent the same entities or objects but with varying integer values. These values directly impact the final result displayed to the user. Whenever any of the input values change, a function needs to be triggered to ...

Treating generics as a concrete value in TypeScript

Experimenting with generics in typescript led me to face a frustrating challenge with a perplexing error message from typescript. My attempt to create a wrapper for generating classes with a common base class ended in encountering the following error mes ...

Error: In Typescript, it is not possible to assign the type 'false' to type 'true'

Currently, I am exploring Angular 2 and encountered a situation where I set the variable isLoading to true initially, and then switch it to false after fetching required data. However, upon executing this process, I encountered the following error message: ...

Unexpected error: Angular 4 TypeScript validation issue - An object literal can only define recognized properties

excellent customer service import {Account} from '../models/Account'; export class AccountingService { domain: string = "http://localhost:3000/api"; constructor(private http: HttpClient) { } getAccounts(){ return this.http.get&l ...

The specified property is not found within this type (Union type)

When working with one of multiple interfaces, I encounter an issue in Vue where it claims the property does not exist. export interface Link { to: string text?: string; } export interface Text { text: string; } export interface Html { html: string ...