简体   繁体   中英

c# Btrieve 6.15 error 22

I use the following code to collect data from a BTrieve 6.15 database file based on the WBTRV32.dll I get allways the error code 22 back at the position reading the next dataline - is it a Problem that my BTrieve file has not fixed column width's?

// Open file
RecordBuffer dataBuffer = new RecordBuffer();
int bufferLength = System.Runtime.InteropServices.Marshal.SizeOf(dataBuffer);
short status = (short)BTRCALL(0, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0);

        if (status == 0) <== Here Status = 0
        {
            // Get first record
            dataBuffer = new RecordBuffer();
            status = (short)BTRCALL(12, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0); //BGETFIRST

            if (status == 0) <== Here Status = 0
            {
                ...                
            }

            // Get subsequent records
            while (status == 0) // BReturnCodes.END_OF_FILE or an error will occur
            {
                dataBuffer = new RecordBuffer();
                status = (short)BTRCALL(6, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0); //BGETNEXT

                if (status == 0) <=== Here Status = 22 data buffer length overrun
                {

                }
            }

}

The status 22 means "data buffer too short". As per the documentation :

Set the Data Buffer Length to a value greater than or equal to the length of the record you want to retrieve.

You need to make sure the Data Buffer Length is set to the proper value before each call. In your code, you only set the bufferLength variable once. If you have variable length records, that value is set on return to the length of the record so you, as the developer, know how much data was returned. Before the next GET call, you need to reset it to the maximum you expect to return.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM