老贴改错,关键字:VC ODBC BLOB ORACLE
我在做一个图像数据库的项目,初学乍练的,在CSDN上到处找资料,网友hahu帮我找到一个CSDN上的老贴子:http://www0.ccidnet.com/tech/guide/2000/11/08/58_1284.html
正好是讲用BLOB存入大对象然后取出存到本地文件夹,欣喜若狂,立马试验了一把。我没按帖子中的那一套来,建立项目时直接选择了“数据库使用文件支持”,改了几个文中的语法小错误后,程序顺利编译成功,但当我运行程序添加记录时,程序报错:“ORA-03113:通信信道的文件结束”,当试图再次添加时就提醒“ORA-03114:未连接到ORACLE",我找不到这两个错误的产生原因,只好老老实实按照老贴文中的步骤一步一步来做,调试也没错,但当运行程序时就提示:Debug Assertion Failed!,并且没有具体原因信息,我把我第一次做的程序的相关部分代码贴在下面,那位大虾能帮我看看?多谢了
问题点数:20、回复次数:5Top
1 楼weiliishere()回复于 2004-05-03 13:12:26 得分 0
// lobthreeView.cpp : implementation of the CLobthreeView class
//
#include "stdafx.h"
#include "lobthree.h"
#include "lobthreeSet.h"
#include "lobthreeDoc.h"
#include "lobthreeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView
IMPLEMENT_DYNCREATE(CLobthreeView, CRecordView)
BEGIN_MESSAGE_MAP(CLobthreeView, CRecordView)
//{{AFX_MSG_MAP(CLobthreeView)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_GET, OnGet)
ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView construction/destruction
CLobthreeView::CLobthreeView()
: CRecordView(CLobthreeView::IDD)
{
//{{AFX_DATA_INIT(CLobthreeView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CLobthreeView::~CLobthreeView()
{
}
void CLobthreeView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLobthreeView)
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_REGISTERNUM, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CLobthreeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CLobthreeView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_lobthreeSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView printing
BOOL CLobthreeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLobthreeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLobthreeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView diagnostics
#ifdef _DEBUG
void CLobthreeView::AssertValid() const
{
CRecordView::AssertValid();
}
void CLobthreeView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CLobthreeDoc* CLobthreeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLobthreeDoc)));
return (CLobthreeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView database support
CRecordset* CLobthreeView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CLobthreeView message handlers
void CLobthreeView::OnAdd()
{
// TODO: Add your control notification handler code here
m_pSet->AddNew();
UpdateData(TRUE);
CFile fileword;
CFileStatus fileStatus;
CString fileLocate;
static char BASED_CODE szFilter[]="WORD Files ( .doc)| .doc||";
//CFileDialog dlg(TRUE,NULL,NULL,0,szFilter,this);
CFileDialog dlg(TRUE,NULL,NULL,0,NULL,this);
if(dlg.DoModal()==IDOK)
fileLocate=dlg.GetPathName();
else
fileLocate="";
if(fileLocate=="")
AfxMessageBox("you don't choise file");
else
{
fileword.Open(fileLocate,CFile::modeRead);
fileword.GetStatus(fileStatus);
m_pSet->m_REPORT.m_hData=GlobalAlloc(GPTR,fileStatus.m_size);
HGLOBAL hGlobal=GlobalAlloc(GPTR,fileStatus.m_size);
m_pSet->SetFieldDirty(&m_pSet->m_REPORT);
m_pSet->SetFieldNull(&m_pSet->m_REPORT,FALSE);
m_pSet->Update();
GlobalUnlock(hGlobal);
}
}
void CLobthreeView::OnGet()
{
// TODO: Add your control notification handler code here
try
{
if(m_pSet->IsEOF())
AfxMessageBox("no record");
else
{
HANDLE hFind;
WIN32_FIND_DATA findData={0};
hFind=FindFirstFile("E:\\STUDY MATERIAL\\FtpUpload\\lobthree\\tyj.doc",&findData);
if(hFind==INVALID_HANDLE_VALUE)
AfxMessageBox("temporary file don't exist");
else
{
AfxMessageBox("temporary file exist");
DeleteFile("E:\\STUDY MATERIAL\\FtpUpload\\lobthree\\tyj.doc");
}
CString strFileName="E:\\STUDY MATERIAL\\FtpUpload\\lobthree\\tyj.doc";
CFile outFile(strFileName,CFile::modeCreate|CFile::modeWrite);
LPSTR buffer = (LPSTR)GlobalLock(m_pSet->m_REPORT.m_hData);
outFile.WriteHuge(buffer,m_pSet->m_REPORT.m_dwDataLength);
GlobalUnlock(m_pSet->m_REPORT.m_hData);
outFile.Close();
ShellExecute(NULL,NULL,_T("tyj.doc"),NULL,_T("E:\\STUDY MATERIAL\\FtpUpload\\lobthree\\"),NULL);
}
}
catch(CException pE)
{
pE.ReportError();
pE.Delete();
return;
}
}
void CLobthreeView::OnUpdate()
{
// TODO: Add your control notification handler code here
m_pSet->Edit();
UpdateData(TRUE);
CFile fileword;
CFileStatus fileStatus;
CString fileLocate;
static char BASED_CODE szFilter[]="WORD Files ( .doc)| .doc||";
CFileDialog dlg(TRUE,NULL,NULL,0,szFilter,this);
if(dlg.DoModal()==IDOK)
fileLocate=dlg.GetPathName();
else
fileLocate="";
if(fileLocate=="")
AfxMessageBox("you don't choise file");
else
{
fileword.Open(fileLocate,CFile::modeRead);
fileword.GetStatus(fileStatus);
m_pSet->m_REPORT.m_hData=GlobalAlloc(GPTR,fileStatus.m_size);
HGLOBAL hGlobal=GlobalAlloc(GPTR,fileStatus.m_size);
m_pSet->SetFieldDirty(&m_pSet->m_REPORT);
m_pSet->SetFieldNull(&m_pSet->m_REPORT,FALSE);
m_pSet->Update();
GlobalUnlock(hGlobal);
}
}
Top
2 楼Mackz(在相互)回复于 2004-05-04 00:05:29 得分 20
原帖代码没有大的错误,就是CFile打开了没有关闭。可是你的代码错误连篇,再好好看看,对照一下。比如:
m_pSet->m_REPORT.m_hData=GlobalAlloc(GPTR,fileStatus.m_size);
HGLOBAL hGlobal=GlobalAlloc(GPTR,fileStatus.m_size);
看看原文是怎么样的。
Top
3 楼Mackz(在相互)回复于 2004-05-07 21:47:05 得分 0
CFile::CFile
The default constructor does not open a file but rather sets m_hFile to CFile::hFileNull.
CFile( );
CFile(
HANDLE hFile
);
CFile(
LPCTSTR lpszFileName,
UINT nOpenFlags
);
Parameters
hFile
The HFILE returned from a previous call to CreateFile, as described in the Platform SDK.
lpszFileName
A string that is the path to the desired file. The path can be relative or absolute.
nOpenFlags
Sharing and access mode. Specifies the action to take when opening the file. You can combine options listed below by using the bitwise-OR (|) operator. One access permission and one share option are required; the modeCreate and modeNoInherit modes are optional. The values are as follows:
CFile::modeCreate Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length.
CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
CFile::modeRead Opens the file for reading only.
CFile::modeReadWrite Opens the file for reading and writing.
CFile::modeWrite Opens the file for writing only.
CFile::modeNoInherit Prevents the file from being inherited by child processes.
CFile::shareDenyNone Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.
CFile::shareDenyRead Opens the file and denies other processes read access to the file. Create fails if the file has been opened in compatibility mode or for read access by any other process.
CFile::shareDenyWrite Opens the file and denies other processes write access to the file. Create fails if the file has been opened in compatibility mode or for write access by any other process.
CFile::shareExclusive Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.
CFile::shareCompat This flag is not available in 32 bit MFC. This flag maps to CFile::shareExclusive when used in CFile::Open.
CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only).
CFile::typeBinary Sets binary mode (used in derived classes only).
CFile::osNoBuffer See FILE_FLAG_NO_BUFFERING in CreateFile in the Platform SDK.
CFile::osWriteThrough See FILE_FLAG_WRITE_THROUGH in CreateFile in the Platform SDK.
CFile::osRandomAccess See FILE_FLAG_RANDOM_ACCESS in CreateFile in the Platform SDK.
CFile::osSequentialScan See FILE_FLAG_SEQUENTIAL_SCAN in CreateFile in the Platform SDK.
Remarks
Because this constructor does not throw an exception, it does not make sense to use TRY/CATCH logic. Use the Open member function, then test directly for exception conditions. For a discussion of exception-processing strategy, see the article Exceptions.
The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.
The constructor with two arguments creates a CFile object and opens the corresponding operating-system file with the given path. This constructor combines the functions of the first constructor and the Open member function. It throws an exception if there is an error while opening the file. Generally, this means that the error is unrecoverable and that the user should be alerted.
Example
For an example using the default constructor, see CFile::Open. For an example using the constructor which throws exceptions, see CATCH.
The HANDLE constructor can be used as in the following code, which creates a file named C:\MyFile.DAT and writes the ANSI characters "Hockey is best!":
HANDLE hFile = CreateFile(_T("C:\\MyFile.DAT"),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
// Attach a CFile object to the handle we have.
CFile myFile(hFile);
static const char sz[] = "Hockey is best!";
// write string, without null-terminator
myFile.Write(sz, lstrlen(sz));
// We can call Close() explicitly, but the destructor would have
// also closed the file for us. Note that there's no need to
// call the CloseHandle() on the handle returned by the API because
// MFC will close it for us.
myFile.Close();
}
要学会用MSDN,其实你要的都有。
Top
4 楼Mackz(在相互)回复于 2004-05-07 21:50:19 得分 0
再贴一点MSDN上的内容:
打开文件
在 MFC 中,最常用的打开文件的方法是一个两步过程。
打开文件
创建文件对象,但不指定路径或权限标志。
通常通过在堆栈帧上声明 CFile 变量来创建文件对象。
调用文件对象的 Open 成员函数,并提供路径和权限标志。
如果曾经成功地打开文件,则 Open 函数返回非零值,如果未能打开指定的文件,则返回 0。Open 成员函数的原型如下:
virtual BOOL Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL );
打开标志指定要为文件设置的权限,如只读。可能的标志值被定义为 CFile 类内的枚举常数,因此用“CFile::”限定它们,与在 CFile::modeRead 中一样。如果要创建该文件,则使用 CFile::modeCreate 标志。
下例说明如何创建具有读/写权限的新文件(替换任何以前具有相同路径的文件):
char* pszFileName = "c:\\test\\myfile.dat";
CFile myFile;
CFileException fileException;
if ( !myFile.Open( pszFileName, CFile::modeCreate |
CFile::modeReadWrite, &fileException ) )
{
TRACE( "Can't open file %s, error = %u\n",
pszFileName, fileException.m_cause );
}
注意 此例创建并打开一个文件。如果存在问题,Open 调用会在最后一个参数中返回一个 CFileException 对象,如此例所示。TRACE 宏既输出文件名也输出指示失败原因的代码。如果需要更详细的错误报告,可以调用 AfxThrowFileException 函数。
------------------------------------------------
读/写文件
如果已使用 C 运行时库文件处理函数,则 MFC 读/写操作看上去将很相似。本文描述如何直接读/写 CFile 对象。还可以使用 CArchive 类进行缓冲的文件 I/O。
读/写文件
使用 Read 和 Write 成员函数读/写文件中的数据。
- 或 -
Seek 成员函数也可用于在文件内移动到特定的偏移量。
Read 成员函数使用指向缓冲区的指针和要读取的字节数,并返回所读取的实际字节数。如果由于到达文件尾 (EOF) 而未能读取所需的字节数,则返回实际读取的字节数。如果发生任何读取错误,则引发异常。Write 与 Read 相似,但不返回写入的字节数。如果发生写入错误(包括不能写入全部指定字节),则引发异常。如果有有效的 CFile 对象,则可以读/写此对象,如下例所示:
char szBuffer[256];
UINT nActual = 0;
CFile myFile;
myFile.Write( szBuffer, sizeof( szBuffer ) );
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read( szBuffer, sizeof( szBuffer ) );
注意 通常应在 try/catch 异常处理块内执行输入/输出操作。
------------------------------------
关闭文件
在 I/O 操作中,文件用完后,通常必须关闭文件。
关闭文件
使用 Close 成员函数。此函数关闭文件系统文件并在必要时刷新缓冲区。
如果在帧上分配了 CFile 对象(如打开文件中的示例所示),当对象超出范围时将自动关闭并随即销毁。注意,删除 CFile 对象并不删除文件系统中的物理文件。
----------------------------------------
访问文件状态
CFile 还支持获取文件状态,包括文件是否存在、创建与修改的日期和时间、逻辑大小和路径。
获取文件状态
使用 CFile 类获取并设置有关文件的信息。一个有用的应用是使用 CFile 静态成员函数 GetStatus 确定文件是否存在。如果指定的文件不存在,则 GetStatus 返回 0。
因此,可以使用 GetStatus 的结果确定打开文件时是否使用 CFile::modeCreate 标志,如下例所示:
CFile theFile;
char* szFileName = "c:\\test\\myfile.dat";
BOOL bOpenOK;
CFileStatus status;
if( CFile::GetStatus( szFileName, status ) )
{
// Open the file without the Create flag
bOpenOK = theFile.Open( szFileName,
CFile::modeWrite );
}
else
{
// Open the file with the Create flag
bOpenOK = theFile.Open( szFileName,
CFile::modeCreate | CFile::modeWrite );
}
Top
5 楼Mackz(在相互)回复于 2004-05-07 21:52:19 得分 0
帖这么多东西,没别的意思,主要是说:MSDN上有很多东西能够回答编程中的疑问;很多高手只不过会查资料、勤于查资料而已。Top
相关问题
- 不用ODBC在VC中用ADO连接Oracle数据库怎样
- 100等你拿!有关VC、ADO、ORACLE及BLOB(大对象) (内详)
- 在vc中用odbc访问oracle数据库,怎么调用其中的sp?
- 在vc中用odbc访问oracle数据库,怎么调用其中的sp?
- 在VC中如何用ODBC的方式调用ORACLE的存储过程?(急)
- 怎么实现用ODBC读取Oracle中的Blob字段,up有分
- 急,急,急,VB中怎样取到oracle中的blob格式的图片?不用odbc怎样连oracle?
- 在VC++里如何通过ADO访问ORACLE里的BLOB字段内容?
- 用VC填写Oracle中的一个BLOB字段的内容,出现问题。
- 急!vc使用ADO访问ORACLE数据库,怎样读写BLOB字段?




