I need to read a FoxPro Dbf File and recreate same in c++; I installed foxpro driver version 9.0 but it did not appeared in driver list in windows DSN. I then installed foxpro from visual studio 6 setup and that showed the driver there and I was able to make connection using it through ADO .Problem is that
_ConnectionPtr m_pCon;
_RecordsetPtr m_pRecordset;
AfxOleInit();
_bstr_t bt1(PassedCstringDirectory);//PassedCstringDirectory passed as argument
_bstr_t bt(sqlcmd);//sqlcmd passed as argument
m_pCon.CreateInstance(__uuidof(Connection));
HRESULT hr;
VARIANT *rowseffected=NULL;
try
{
//The SourceDB should be a proper directory
hr=m_pCon->Open("Provider=VFPOLEDB; SourceType=DBF; "
"SourceDB="+bt1+";Extended Properties=FoxPro 3.0;", "","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("Connection failed, check the direction!");
}
m_pCon->Execute(bt,rowseffected,adConnectUnspecified);
m_pCon->Execute() is returning false(S_FALSE) but files (dbf and fpt) are being created .and i am not able to insert data into files .error being ."Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype."
Related
I am using Microsoft Visualstudio2015, i am trying to run c++ program using OCI functions, but my program terminating.
I set ocilib path in my visual studio and it starting successfully, but i got message initialising failed in my log file
#include "ocilib.h"
ofstream LogFile;
LogFile.open("logfile.txt");
void err_handler(OCI_Error *err)
{
if(OCI_ErrorGetType(err) == OCI_ERR_ORACLE)
{
const mtext* sql =OCI_GetSql(OCI_ErrorGetStatement(err));
if(sql != NULL)
{
LogFile<<"ERROR - SQL : "<<sql<<"\n";
}
}
LogFile<<"ERROR - MSG : "<<OCI_ErrorGetString(err)<<endl;
++nbr_error;
}
if(!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
{
LogFile<<"ERROR - Initialise failed\n";
exit(1);
}
After running the program It shows ERROR - MSG: Cannot create OCI environment Program terminating,
what i supposed to do.
Download instantclient-basic and instantclient-sdk-windows from http://www.oracle.com/technetwork/cn/topics/winsoft-085727.html.
You should choose the x86 or the x64 version based on your program.
And then decompress and merge them to one folder.
In your program,
OCI_Initialize(err_handler, the_folder, OCI_ENV_DEFAULT)
Re-check your OCILIB path in Environment variables,
for example:-
Copy ocilib\include\ocilib.h : to a folder listed in the compiler headers folders
Copy ocilib\lib32 |64\ocilib [x].Lib : to a folder listed in the linker libraries folders
Copy ocilib\lib32|64\ocilib [x]. Dll : to a folder included in the PATH environment variable
I tried to connect the oracle XE (11.2.0.2.0) database using VC++ MFC (Visual Studio 2012). Below is a example code given at oracle website.
void CMFCOracleOCCIDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
const string userName = "<username>";
const string password = "<password>";
const string connectString = "";
Environment *env = Environment::createEnvironment();
{
Connection *conn = env->createConnection(userName, password, connectString);
Statement *stmt = conn->createStatement("SELECT * FROM tab");
ResultSet *rs = stmt->executeQuery();
for(int i=1;i<20;i++){
rs->next();
//Below are the commented 4 lines
/*
string s = rs->getString(1);
CString str2(s.c_str());
lstBox01.AddString(str2);
MessageBox(str2);
*/
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
}
Environment::terminateEnvironment(env);
}
In the above code while the 4 line in comment, it works fine. Otherwise it works for only one loop (i=1) and display the proper message (for only 1 time). After that, getting the below error
First-chance exception at 0x51A4CCC8 (msvcp110d.dll). After selecting the break it goes to the file xutility and function
inline void _Container_base12::_Orphan_all()
How to solve this error?
Usually what is best practice to connect oracle using VC++ MFC?
Environment :
Windows 8.1 (64)
Oracle XE (11.2.0.2.0)
OCCI Library : Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
Download instantclient-sdk-nt-11.2.0.2.0.zip
Visual Studio 2012 (Debug - Configuration)
Edit
This error raised in-case of getString() (varchar2 field). When using integer field with getInt(), it is working fine.
I'm having an absolute nightmare of a time trying to get the Sqlite C++ library to compile in Visual Studio 2013 Ultimate (Compiles fine in VS2012).
Basically regardless of whether I try to perform a clean or a rebuild VS will claim to successfully finish but will subsequently freeze and become unresponsive, never to recover.
Here is the output
and here is the actual VS project.
Anyone care to give it a crack and see if they are running into the same problem or provide any suggestions?
Tim Heuer gives step by step instructions ON THIS LINK. The batch files are hardcoded for TCL 8.5, you'll save yourself some time if you don't download the latest (8.6)
EDITED - I successfully compiled SQLite with Tim's steps (I just reinstalled Windows 8.1 / VS 2013). Note: the only issue I encountered was taking the steps to literally, be sure to change into the newly created SQLite directory before running the fossil command.
FYI for WinRT, be sure to use the correct path, if you just specify the filename you will get an access denied error (which will surface as a "cannot open database" error).
using namespace Windows::Storage;
using namespace std;
void SqliteWrapper::RunTest(void)
{
sqlite3 *db;
int rc;
auto path = ApplicationData::Current->LocalFolder->Path+"\\MyDatabase.db";
string dataPath(path->Begin(), path->End());
rc = sqlite3_open(dataPath.c_str(), &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
}
sqlite3_close(db);
}
I created an MFC application using VC++ 6.0 on my development computer installing Windows XP SP3. In this application, I used ADO objects to access SQL database server :
CoInitialize (NULL);
try
{
_ConnectionPtr pConn;
HRESULT hr = pConn.CreateInstance (__uuidof (Connection));
if (FAILED (hr))
{
AfxMessageBox ("Can't create intance of Connection");
}
//...
}
//...
Of course, the app works fine on my computer. However, I copied the whole Release folder of the app and then run it on another computer with Windows XP SP3 installed, the app failed at creating the Connection object with hr = -2147467262.
I searched on the internet much but don't see any resolution.
Does anyone know this issue and could you give me some guides on that?
I have created simple COM DLL using ATL and have added "ATL Simple Object" after that. To be sure server is registering I have placed messagebox:
STDAPI DllRegisterServer(void)
{
MessageBoxA ( NULL, "Hello World!", "Test", MB_OK );
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
}
Registering does fine. I decided to look how this object looks with OLE-COM Object Viewer that is part of SDK. Viewer reports error:
"LoadTypelib'(c:\pr\ILight.dll) failed.
<No system message defined> STG_E_FILENOTFOUND ($800300002)
Does it means my COM dll corrupted? How to make VIewer to show my dll information?
P.S.
Project RC file contians:
"REGISTRY"
IDR_ILIGHT
HKCR{}
IDR_LIGHT
HKCR
{
AboutiLight.1 = s 'Light Class'
{
CLSID = s '{DBC53EA8-A51E-4374-B104-06A834273B0C}'
}
AboutiLight = s 'Light Class'
{
CurVer = s 'AboutiLight.1'
}
NoRemove CLSID
{
ForceRemove {DBC53EA8-A51E-4374-B104-06A834273B0C} = s 'Light Class'
{
ProgID = s 'AboutiLight.1'
VersionIndependentProgID = s 'AboutiLight'
ForceRemove Programmable
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{1D9F859D-10FF-4827-A341-4A8B8E318A61}'
Version = s '1.0'
}
}
}
String table
String table
ID=IDS_PROJNAME Value=100 Caption ILight
Version
VS_VERSION_INFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEMASK 0x3fL
FILEFLAGS 0x0L
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
After having received the same error (STG_E_FILENOTFOUND), and seeing Joe Willcoxson's comment about 64-bit and 32-bit, I was able to find a solution.
If you are using OleView.exe, the OLE/COM Object Viewer, there are actually two versions of it: 32-bit, and 64-bit. Ensure that you are launching with the proper version of OleView. The version in the base "BIN" folder of the SDK will be the 32-bit version. The "x64" folder will have the 64-bit version of the application, which is not fully compatible with older binaries and their typelibs (made in a 32-bit world).
On the other hand, if your new DLL is actively being compiled for x64, then it's highly likely 32-bit OleView will not be able to read the data properly, either.
1) Check to make sure that is the right path to your DLL.
2) Open the DLL itself from Visual Studio and check to be sure that a type library is embedded in the resources. If a typelib isn't found, add one.
3) If all that fails, did you register it under an administrator account/shell. If you call regsvr32.exe on it, make sure you are running with elevated privileges.