Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
My Question is my MFC application will read sqlite db file when user use my application, but after user finished read db file, user will click update db file ,I need to download a new version db file from FTP Server. But the application catch CFileException tell me share permission conflict. My thought is I didn't close the db database although I write sqlite3_close(db) behind all sqlite3_open;
So what should I do?
And code below is what I use to download file from FTP
UINT FTPThread(LPVOID pParam)
{
	char filebuf[4096]={0};
	CInternetFile	*pFTPFile;
	CInternetSession	*m_pInetSession;
	CFtpConnection	*m_pFtpConnection;
 
	//setup login info
	CString user_name = "******";
	CString password = "***********";
	int port = 21;
	CString Server_IP = "**********";
	CString file_dir = "\\******\\*******\\";
	CString file_name = "test.db";
 
	
	CFtpFileFind *m_finder = NULL;
	//connect FTP
	try
	{
	m_pInetSession = new CInternetSession();
	m_pFtpConnection = m_pInetSession->GetFtpConnection(Server_IP,user_name, password,port);
 

	}
	catch(CInternetException *e)
	{
		CString szError;
		TCHAR t_error[255];
 
		e->GetErrorMessage(t_error,255);
		szError = t_error;
 
		AfxMessageBox(szError,MB_ICONINFORMATION);
		e->Delete();
		m_pFtpConnection = NULL;
	}
	//download file
	try
	{
		//search file in FTP
		m_pFtpConnection->SetCurrentDirectory(file_dir);
		m_finder = new CFtpFileFind(m_pFtpConnection);
		bool bFinder = m_finder->FindFile(file_name);
 
		if (bFinder)
		{
			//find file and open it
			pFTPFile = m_pFtpConnection->OpenFile(file_name,GENERIC_READ);
 
			m_finder->FindNextFile();
 
			//create file in local
			try
			{
//Exception catched from here 
CFile local_file(pFTPFile->GetFileName(),CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
		//how many byte alreadt wirte
				int bytewirte = 0;
				//check bytewrite
				while (bytewirte = pFTPFile->Read(filebuf,4096))
				{
					local_file.Write(filebuf,bytewirte);
 
				}
				local_file.Close();
				//AfxMessageBox("db file donw!",MB_ICONINFORMATION);
				HWND hWnd = FindWindow(NULL, "download_dlg");
				SetWindowText(GetDlgItem(hWnd,IDC_CURRENT_STATUS_STATIC),"download done!");
				EnableWindow(GetDlgItem(hWnd,IDC_BTN_DOWNLOAD_OK),TRUE);
				UpdateWindow(hWnd);
 
			}
			catch (CFileException* e)
			{
				CString szError;
				TCHAR t_error[255];
 
				e->GetErrorMessage(t_error,255);
				szError = t_error;
				e->Delete();
			}
 
		}
		else
		{
			AfxMessageBox("can not find db file in FTP server!",MB_ICONINFORMATION);
 
		}
	}
	catch (CInternetException* pEx)
	{
		CString szError;
		TCHAR t_error[255];
 
		pEx->GetErrorMessage(t_error,255);
		szError = t_error;
		delete pFTPFile;
		pEx->Delete();
	}
	delete pFTPFile;
 
	return 0;
 
}
Posted 16-Jan-13 23:02pm
Comments
Mohibur Rashid at 17-Jan-13 4:41am
   
First make sure your code can download any file at all. then you will know certainly whether it is related with your closing file or not
Richard MacCutchan at 17-Jan-13 6:20am
   
Where exactly do you get the error?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

read sqlite documents, then I know I have to finilize stmt before I close db.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100