Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Btrieve v6.15 Error 51

Status
Not open for further replies.

Shaga

Programmer
Apr 1, 2003
11
0
0
GB
Hi,

I can successfully open a Btrieve file with the owner set with BUTIL, but when I attempt to open it via code (C#) I get an error 51 "Invalid Owner"! I have set the owner name in the following Structure, it is 6 chars in length so have set the dataLen to 7 to allow for the binary 0 at the end:

[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi, Size=8)]
public struct BTR_OWNER_NAME
{
public string OwenerName;
}

but when I attempt top open the file with:

bStat = BtrCall.BTRCALL( (ushort)BTROPS.B_OPEN, posBlock, ref ownerBuf, ref dataLen, keyBuffer, keyLen, keyNum );

I get the error 51!!!! Can someone PLEASE assist.
 
I was this in the documentation:

If this status code occurred during an Open operation or a DROP TABLE statement, the application attempted to open a file that has an owner name assigned to it. The application must specify the correct owner name in the data buffer. Ensure that the owner name is null-terminated in the data buffer and that the data buffer length is set long enough to include the owner name plus the null terminator.

This might not make any difference, but you have the following line:

public string OwenerName;

I don't know C all that well but could it be that the variable should be OwnerName and a blank value is being passed instead of the actual owner name.

Hope this helps...
 
Prior to the Open I was assigning the owner name as follows:

ownerBuf.OwenerName = OWNER_NAME;

The OWNER_NAME const has a string as is:

OWNER_NAME = "mypass";

... and I have set the dataLen to 1 more than the number of chars and have even looped through the struct to check that it is terminated with a binary null, and it is. It is also the correct owner name as I set it with BUTIL and have since cleared it again.

When the owner name is not set and I open with a IntPtr.Zero this works fine, but when I open with a ref to my struct then I get error 51 despite the correct owner name having been set on the struct!!!
 
For the record I have solved it thus:

Create a structure in which to store the Owner Name:

[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi, Size=8)]
public struct BTR_OWNER_NAME
{
public string OwenerName;
}

//Declare a struct var:

BTR_OWNER_NAME ownerBuf;

//Assign the constant in which the Owner Name is held (this contains 6 chars):

ownerBuf.OwenerName = OWNER_NAME;

//Pass the length of the Owner Name +1 for the trailing Binary 0 into var:

dataLen = 7;

// move our owner structure into unmanaged memory block
dataBuffer = Marshal.StringToHGlobalAnsi(ownerBuf.OwenerName);

// and finally issue OPEN (0) operation to Btrieve with the dataBuffer containg the Owner Name:

try
{
bStat = BtrCall.BTRCALL( (ushort)BTROPS.B_OPEN, posBlock, dataBuffer, ref dataLen, keyBuffer, keyLen, keyNum );
}
catch( Exception e )

bStat has been assigned 0, so all is fine and the Btrieve file which has an Owner Name set with access level 0 is now open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top