Hi All:
Dev env. VC++ .NET SQL Server 2000 Win2k Advanced Server
I'm trying to write some BLOB data to a field on my database. I want
perform this using a stored procedure whos expect like 3rd parameter a
BLOB. also I 'm using the Parameter's Object AppendChunk method and when
I try to call it
I got the following error:
Operation not allowed on this context!!!
Here list my code:
BOOL CDBManager::InsertPublication(long lPubID, const char* pszPubTitle,
const char* pszPubContent)
{
_CommandPtr theCommand;
BOOL bRet;
HRESULT hr;
VARIANT vChunk;
try{
if(!m_bConnected)return FALSE;
bRet = FALSE;
hr = theCommand.CreateInstance(__uuidof(Command));
if(SUCCEEDED(hr)){
theCommand->put_ActiveConnection(_variant_t(m_Connection, false));
theCommand->put_CommandText(_bstr_t(SPN_INSERT_PUBLICATION));
theCommand->put_CommandType(adCmdStoredProc);
//setting up parameters
//Append the first parameter (theme ID)
hr = theCommand->GetParameters()->Append(theCommand->CreateParameter(_bstr_t("Theme"),
adInteger,
adParamInput,
sizeof(long),
_variant_t(lPubID)));
if(SUCCEEDED(hr)){
//Append the 2nd parameter (the publication title)
hr = theCommand->GetParameters()->Append(theCommand->CreateParameter(_bstr_t("Title"),
adBSTR,
adParamInput,
strlen(pszPubTitle),
_variant_t(pszPubTitle)));
if(SUCCEEDED(hr)){
//Append the 3rd parameter (the contents) I mean the BLOB...
_ParameterPtr theBlob;
long length;
SAFEARRAY* psa;
SAFEARRAYBOUND rgsabounds[1];
char szString[1024];
//Create the 3rd parametetr
length = strlen(pszPubContent);
theBlob = theCommand->CreateParameter( _bstr_t("Article"),
(DataTypeEnum)(adArray | adChar),
adParamInput,
length);
//create a safe array of length bytes to store data
rgsabounds[0].lLbound = 0;
rgsabounds[0].cElements = length;
psa = SafeArrayCreate(VT_UI1, 1, &rgsabounds[0]);
if(psa != NULL){
//copies byte to byte the contents for the array
for(long index = 0; index < length; index++)
SafeArrayPutElement(psa, &index, (void*)&pszPubContent[index]);
vChunk.vt = VT_ARRAY | VT_UI1;
vChunk.parray = psa;
//Appends the chunk inside the parameter
theBlob->AppendChunk(vChunk);
//Add parameter to parameters collectio for current command
hr = theCommand->GetParameters()->Append(theBlob);
if(SUCCEEDED(hr)){
_variant_t vError;
vError.vt = VT_ERROR;
vError.scode = DISP_E_PARAMNOTFOUND;
//Executes the command
theCommand->Execute(&vError, &vError, adExecuteNoRecords);
bRet = TRUE;
}
//Cleanup array and variants...
SafeArrayDestroy(psa);
}
}
}
//Cleanup the connection
theCommand->putref_ActiveConnection(NULL);
theCommand = NULL;
}
}
catch(_com_error& e){
ManageCOMError(e);
}
catch(...){
ManageError("Unknown Error");
}
return bRet;
}
Any suggestion about the problem will be very helpful
Thanks in advance
==========================================
Lic. Yosvel Reyes Fonfria
[EMAIL PROTECTED]
tel: (053)42 205428
Who try and try again, triumph!!!
==========================================
--
http://www.fastmail.fm - Sent 0.000002 seconds ago
