Forum Stats

  • 3,826,047 Users
  • 2,260,590 Discussions
  • 7,896,779 Comments

Discussions

TNS Packet writer failure and end-of-file on communication channel

677886
677886 Member Posts: 6
edited Nov 19, 2010 10:28PM in Oracle Provider for OLE DB
Hello Sir/Mam,
I m working on oracle server 9i. when i insert data into Blob,Nclob,Clob field which is larger than 4KB, this message occur everytimes.(TNS Packet writer failure or end-of-file on communication channel).

Can u tell me why this happen when i insert large data from 4KB.

I m using oledb to insert data into a table.if datasize is less than 4 KB ,its easily insert.

My Code Module is this

BOOL CconnectivityDlg::OpenOracleFile()
{

BOOL bResult=FALSE;
bFile = FALSE;
dwFileSize = 0;
CString csVirtualPath;
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
{
StrName = dlg.GetPathName();
}
hFile1=CreateFile(StrName,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
NULL,OPEN_EXISTING, NULL,NULL);
unsigned int count =0;


if(hFile1==INVALID_HANDLE_VALUE)
{
if(count<5)
{
count++;
Sleep(1000);
}
else
{
return bResult;
}
}

DWORD dwHighPart,dwLowPart;
dwLowPart = GetFileSize(hFile1,&dwHighPart);
LARGE_INTEGER NewFilePointer;
NewFilePointer.LowPart = dwLowPart;
NewFilePointer.HighPart = dwHighPart;
dwFileSize = NewFilePointer.QuadPart;
bFile = TRUE;
bResult = TRUE;
if(hFile1)
{
CloseHandle(hFile1);
hFile1 =NULL;
}
return bResult;
}

BOOL CconnectivityDlg::CreateConnection()
{
BOOL bResult = FALSE;
CString Count,strFileSaveName;
Count.Empty();
strFileSaveName.Empty();
unsigned int nCounter = 0;
repeat:
if(!AfxOleInit())
{
return FALSE;
}
m_pConn.CreateInstance (__uuidof(Connection));
CString strConn ;
strConn.Empty();
m_pConn->CursorLocation = adUseClient;
strConn =_T("Provider=MSDAORA;OSAuthent=1;Data Source =LOVE;Connect as =SYSDBA;");
try
{
m_pConn->Open(_bstr_t(strConn),_bstr_t("system"),_bstr_t("system"),adConnectUnspecified);
bResult = TRUE;

}
catch(_com_error& e)
{
CString sBuff = GetErrorDescription(e);
AfxMessageBox(sBuff);
return 0;
}
catch(...)
{
AfxMessageBox(_T("UnknownError"));
return 0;
}

m_pCom.CreateInstance(__uuidof(Command));
try
{
m_pCom->ActiveConnection = m_pConn;
}
catch(_com_error& e)
{
CString sBuff = GetErrorDescription(e);
AfxMessageBox((sBuff));

}
catch(...)
{
AfxMessageBox(_T("UnknownError"));
}

return bResult;

}
CString CconnectivityDlg::insertimage()
{
CString Query,ColmnName;
Query.Empty();
ColmnName = _T("FIRST");//Coloumn Name
Query = _T("insert into SINGLE(FIRST) values (?)"); //Table in which i want to insert data of Nclob type.
hFile1 = CreateFile(StrName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);//File from i read the data to insert into nclob field
DWORD dwHighPart,dwLowPart;
dwLowPart = GetFileSize(hFile1,&dwHighPart);
LARGE_INTEGER NewFilePointer;
NewFilePointer.LowPart = dwLowPart;
NewFilePointer.HighPart = dwHighPart;
dwFileSize = NewFilePointer.QuadPart;
BYTE *ImageData = new BYTE[dwFileSize+2];
memset(ImageData,0,dwFileSize+2);
BOOL bRead = ReadFile(hFile1,ImageData,dwFileSize,&dw,NULL);

VARIANT varChunk;
long lngOffset=0;
UCHAR chData;
SAFEARRAY FAR *psa = NULL;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound=0;
rgsabound[0].cElements=dwFileSize;
psa = SafeArrayCreate(VT_UI1,1,rgsabound);
HRESULT hr;
while(lngOffset < (long)dwFileSize)
{
chData = ((UCHAR*)ImageData)[lngOffset];
hr = SafeArrayPutElement(psa,&lngOffset,&chData);
lngOffset++;
}
lngOffset = 0;
varChunk.vt=VT_ARRAY|VT_UI1;
varChunk.parray=psa;
try
{

m_pCom->Parameters->Append(m_pCom->CreateParameter(_bstr_t(ColmnName),adLongVarWChar,adParamInput,(ADO_LONGPTR)dwFileSize,varChunk));
VariantClear(&varChunk);
}
catch(_com_error& e)
{
CString sBuff = GetErrorDescription(e);
AfxMessageBox(sBuff);
}
if(ImageData)
{
delete[] ImageData;
ImageData = NULL;
}
try
{

m_pCom->CommandText=_bstr_t(Query);
m_pConn->CursorLocation = adUseClient;
m_pCom->CommandTimeout=0;
m_pCom->Execute(NULL,NULL,adCmdText);
}
catch(_com_error& e)
{
CString sBuff = GetErrorDescription(e);
AfxMessageBox(sBuff);
}
return 0;
}
CString CconnectivityDlg::GetErrorDescription(_com_error& e)
{
bstrt bstrSource(e.Source());
bstrt bstrDescription(e.Description());
_TCHAR szTemp[1024];

CString strInfo ;
wsprintf(szTemp, _T("Message : %s\n"), e.ErrorMessage());
strInfo = szTemp;
wsprintf(szTemp, _T("Code : 0x%08lx\n"), e.Error());
strInfo += szTemp;
wsprintf(szTemp, T("Source : %s\n"), bstrSource.length() ? (LPCTSTR)bstrSource : T("null"));
strInfo += szTemp;
wsprintf(szTemp, T("Description : %s\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : T("null"));
strInfo += szTemp;
CString str = strInfo;
if(str.Find(_T("not a valid password"),0) > 0)
strInfo = _T("File is password protected") ;

return strInfo;
}

Answers

This discussion has been closed.