I am very new to Oracle and trying to write a hello world program to connect to the Oracle ODBC through C++ code so that I can get the connection opened and then execute my store procedure. I am using Visual Studio 2017 editor on Windows 10. This is what I am trying to achieve
#include <Windows.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
int main() {
SQLHANDLE g_sqlEnvHandle;
SQLHANDLE g_sqlConnHandle;
SQLRETURN rc;
/* Allocate the Environment Handle */
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &g_sqlEnvHandle);
/* Set the ODBC version environment attribute */
rc = SQLSetEnvAttr(g_sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
/* Allocate connection handle */
rc = SQLAllocHandle(SQL_HANDLE_DBC, g_sqlEnvHandle, &g_sqlConnHandle);
/* Connect to ODBC driver */
char sConnString_in[2000] = "DRIVER={Oracle in OraDB19Home1};SERVER=localhost;UID=system;PWD=abc;DATABASE=mydataBase";
rc = SQLDriverConnect(g_sqlConnHandle, NULL, (SQLCHAR*)sConnString_in, (SQLSMALLINT)lstrlen((char *)sConnString_in), sConnOut, 200, &cbConnStrOut, SQL_DRIVER_NOPROMPT);
}
On debugging the code, I am always getting -1 from SQLDriverConnect. Any help would be appreciated.
Thank.
Related
I am pretty new in ROS. I am just trying to publish a message to a node in a linux server with this code:
#include "stdafx.h"
#include "ros.h"
#include <string>
#include <stdio.h>
#include <Windows.h>
using std::string;
int _tmain(int argc, _TCHAR * argv[])
{
ros::NodeHandle nh;
char *ros_master = "*.*.*.*";
printf("Connecting to server at %s\n", ros_master);
nh.initNode(ros_master);
printf("Advertising cmd_vel message\n");
string sent = "Hello robot";
ros::Publisher cmd_vel_pub("try", sent);
nh.advertise(cmd_vel_pub);
printf("All done!\n");
return 0;
}
The compiler gives me these errors:
Error C2664 'ros::Publisher::Publisher(ros::Publisher &&)': cannot convert argument 2 from 'std::string' to 'ros::Msg *' LeapMotion c:\users\vive-vr-pc\documents\visual studio 2015\projects\leapmotion\leapmotion\leapmotion.cpp 22
Error (active) no instance of constructor "ros::Publisher::Publisher" matches the argument list LeapMotion c:\Users\Vive-VR-PC\Documents\Visual Studio 2015\Projects\LeapMotion\LeapMotion\LeapMotion.cpp 22
I am on Visual Studio and there aren't a lot of tutorial from windows to linux, so I am confused on what to do. Many thanks for the help! :D
Take a look at the Hello World example. You cannot send types which are not defined as messages, i.e. std::string is not a ros message type. What you need is
#include <std_msgs/String.h>
Define and fill the string messages
std_msgs::String sent;
ros::Publisher cmd_vel_pub("try", &sent);
nh.advertise(cmd_vel_pub);
ros::Rate r(1); // once a second
sent.data = "Hello robot";
while (n.ok()){
cmd_vel_pun.publish(sent);
ros::spinOnce();
r.sleep();
}
Check out this blabbler example and these tutorials.
I'm using a led matrix shield (http://www.wemos.cc/Products/oled_shield.html) with a wemos. I'm using Arduino IDE.
The exemples work perfectly (https://github.com/wemos/D1_mini_Examples/tree/master/04.Shields/OLED_Shield/Use_SparkFun_Library)
But when I try to print text, the screen remains empty. Here is my code
#include <Wire.h>
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library
#define PIN_RESET 255
#define DC_JUMPER 0
MicroOLED oled(PIN_RESET, DC_JUMPER);
void setup()
{
oled.begin();
oled.clear(ALL);
oled.clear(PAGE);
oled.display();
oled.setFontType(0);
oled.setCursor(0, 0);
oled.print("Hello, world");
oled.display();
}
void loop()
{
}
Any idea ?
I solved the issue. I modified SFE_MicroOLED lib.
The fonts are loaded in the program memory (via PROGMEM directive). This makes the code fail on wemos.
I remove PROGMEM directive on a fork of this lib (https://github.com/landru29/SparkFun_Micro_OLED_Arduino_Library)
I just check if the arch is ARDUINO_ESP8266_NODEMCU
https://github.com/landru29/SparkFun_Micro_OLED_Arduino_Library/blob/master/src/util/7segment.h#L37 (idem for all other font files in the same folder)
My application uses MS Access mdb files because of legacy reasons. It connects to the database using ADO with the following connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=Dummy.mdb
Recently I started porting my application to 64 bit. Because of that Jet OLEDB provider is not available on 64 bit systems I used ACE OLEDB provider with the following connection string:
Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=Dummy.mdb
The application also uses MS XML DOM to work with XML files. Sometimes the 64 bit version crashes with access violation exception in SysFreeString which is called from one of the MS XML wrapper methods. The 32 bit version does not have these problems. I distilled the problem into the tester applicaiton.
#define _WIN32_WINNT 0x0501
#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <conio.h>
#include <ObjBase.h>
#import <msxml6.dll>
#import <msado15.dll> rename("EOF", "EndOfFile")
using namespace ADODB;
bool s_bRepeat = true;
unsigned __stdcall XmlThreadFunc(void*)
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
MSXML2::IXMLDOMDocumentPtr l_pXMLDom;
l_pXMLDom.CreateInstance(__uuidof(DOMDocument), NULL, CLSCTX_INPROC_SERVER);
l_pXMLDom->async = VARIANT_FALSE;
MSXML2::IXMLDOMElementPtr l_pRoot = l_pXMLDom->createElement("root");
l_pXMLDom->appendChild(l_pRoot);
unsigned int l_nCnt = 0;
while (s_bRepeat)
{
if (0 == l_nCnt++ % 1000)
{
printf(".");
}
l_pRoot->setAttribute("test", "Test1");
Sleep(0);
}
CoUninitialize();
_endthreadex(0);
return 0;
}
unsigned __stdcall DbThreadFunc(void*)
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
_ConnectionPtr l_pConnection;
l_pConnection.CreateInstance(__uuidof(Connection));
#ifdef _WIN64
LPCSTR l_cszConnectStr = "Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=Dummy.mdb";
#else
LPCSTR l_cszConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=Dummy.mdb";
#endif
while (s_bRepeat)
{
l_pConnection->Open(l_cszConnectStr, "", "", adConnectUnspecified);
Sleep(1000);
printf("(");
l_pConnection->Close();
printf(")");
}
CoUninitialize();
_endthreadex(0);
return 0;
}
int main()
{
HANDLE l_hXmlThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &XmlThreadFunc, NULL, 0, NULL));
HANDLE l_hDbThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &DbThreadFunc, NULL, 0, NULL));
_getch();
s_bRepeat = false;
HANDLE l_Handles[2] = { l_hXmlThread, l_hDbThread };
WaitForMultipleObjects(2, l_Handles, TRUE, INFINITE);
CloseHandle(l_hXmlThread);
CloseHandle(l_hDbThread);
return 0;
}
The crash call stack is the following:
OLEAUT32!SysFreeString
TestCrash64Lean!_bstr_t::Data_t::_Free
TestCrash64Lean!_bstr_t::Data_t::~Data_t
TestCrash64Lean!_bstr_t::Data_t::`scalar deleting destructor'
TestCrash64Lean!_bstr_t::Data_t::Release
TestCrash64Lean!_bstr_t::_Free
TestCrash64Lean!_bstr_t::~_bstr_t
TestCrash64Lean!MSXML2::IXMLDOMElement::setAttribute
TestCrash64Lean!XmlThreadFunc
MSVCR80D!_callthreadstartex
MSVCR80D!_threadstartex
kernel32!BaseThreadInitThunk
ntdll!RtlUserThreadStart
At the crash the DB thread is always in the following state:
MSVCR90!memset
mso!Ordinal4118
mso!Ordinal7994
mso!MsoUninitOffice
ACECORE
ACECORE
ACEOLEDB!DllGetClassObject
ACEOLEDB!DllGetClassObject
ACEOLEDB!DllGetClassObject
ACEOLEDB!DllGetClassObject
oledb32!CAcm::FinalRelease
oledb32!ATL::CComPolyObject<CDCM>::~CComPolyObject<CDCM>
oledb32!ATL::CComPolyObject<CDCM>::Release
oledb32!CDCMCreator::DestroyResource
comsvcs!CHolder::SafeDispenserDriver::DestroyResource
comsvcs!CHolder::ProcessDestroyList
comsvcs!CHolder::FreeResource
oledb32!CDCMCreator::ReleaseResource
oledb32!CDPO::ReturnDCMToPool
oledb32!CDPO::FinalRelease
oledb32!ATL::CComPolyObject<CDPO>::`scalar deleting destructor'
oledb32!ATL::CComPolyObject<CDPO>::Release
msado15!CConnection::_Close
msado15!CConnection::Close
TestCrash64Lean!ADODB::Connection15::Close
TestCrash64Lean!DbThreadFunc
MSVCR80D!_callthreadstartex
MSVCR80D!_threadstartex
kernel32!BaseThreadInitThunk
ntdll!RtlUserThreadStart
I found that as a workaround if I keep one open connection to some empty database file, I can open and close connections to actual database files and the application does not crash. Anyway I would rather understand the actual cause of the crash. I would appreciate any suggestions.
My configuration is the following:
Microsoft Visual Studio 2005 Version 8.0.50727.4039 (QFE.050727-4000)
Windows Server 2008 R2 Standard 64 bit
Processor: Intel(R) Xeon(R) E5645 # 2.40GHz
Memory: 16.0 GB
It looks like this is a problem of ACE OLEDB provider from Microsoft Access Database Engine 2010 Redistributable. Switching to the provider from Microsoft Access 2013 Runtime resolved the problem.
Is it possible to side-step _NSGetExecutablePath on Ubuntu Linux in place of a non-Apple specific approach?
I am trying to compile the following code on Ubuntu: https://github.com/Bohdan-Khomtchouk/HeatmapGenerator/blob/master/HeatmapGenerator2_Macintosh_OSX.cxx
As per this prior question that I asked: fatal error: mach-o/dyld.h: No such file or directory, I decided to comment out line 52 and am wondering if there is a general cross-platform (non-Apple specific) way that I can rewrite the code block of line 567 (the _NSGetExecutablePath block) in a manner that is non-Apple specific.
Alen Stojanov's answer to Programmatically retrieving the absolute path of an OS X command-line app and also How do you determine the full path of the currently running executable in go? gave me some ideas on where to start but I want to make certain that I am on the right track here before I go about doing this.
Is there a way to modify _NSGetExecutablePath to be compatible with Ubuntu Linux?
Currently, I am experiencing the following compiler error:
HeatmapGenerator_Macintosh_OSX.cxx:568:13: error: use of undeclared identifier
'_NSGetExecutablePath'
if (_NSGetExecutablePath(path, &size) == 0)
Basic idea how to do it in a way that should be portable across POSIX systems:
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
static char *path;
const char *appPath(void)
{
return path;
}
static void cleanup()
{
free(path);
}
int main(int argc, char **argv)
{
path = realpath(argv[0], 0);
if (!path)
{
perror("realpath");
return 1;
}
atexit(&cleanup);
printf("App path: %s\n", appPath());
return 0;
}
You can define an own module for it, just pass it argv[0] and export the appPath() function from a header.
edit: replaced exported variable by accessor method
The CM108 from C-Media has 4 GPIO pin that you can access via a hid interface.
Using the generic write function in Windows I was able to write to the gpio pins.
However I'm trying to do the same thing in Linux without success.
The linux kernel detect the device as a hidraw device.
Note: I was able to read from the device, just not write. (I've run the app as root just to make sure it wasn't a permission issue).
I got this working, here's how.
I needed to create a new linux hid kernel mod. (it wasn't that hard)/*
/*
* Driver for the C-Media 108 chips
*
* Copyright (C) 2009 Steve Beaulac <steve#sagacity.ca>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*/
/*
* This driver is based on the cm109.c driver
*/
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>
#define DRIVER_VERSION "20090526"
#define DRIVER_AUTHOR "Steve Beaulac"
#define DRIVER_DESC "C-Media 108 chip"
#define CM108_VENDOR_ID 0x0d8c
#define CM108_PRODUCT_ID 0x000c
#ifdef CONFIG_USB_DYNAMIC_MINORS
#define CM108_MINOR_BASE 0
#else
#define CM108_MINOR_BASE 96
#endif
/*
* Linux interface and usb initialisation
*/
static int cm108_hid_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
int ret;
ret = hid_parse(hdev);
if (ret) {
dev_err(&hdev->dev, "parse failed\n");
goto error;
}
ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
if (ret) {
dev_err(&hdev->dev, "hw start failed\n");
goto error;
}
return 0;
error:
return ret;
}
static struct hid_device_id cm108_device_table[] = {
{ HID_USB_DEVICE (CM108_VENDOR_ID, CM108_PRODUCT_ID) },
/* you can add more devices here with product ID 0x0008 - 0x000f */
{ }
};
MODULE_DEVICE_TABLE (hid, cm108_device_table);
static struct hid_driver hid_cm108_driver = {
.name = "cm108",
.id_table = cm108_device_table,
.probe = cm108_hid_probe,
};
static int hid_cm108_init(void)
{
return hid_register_driver(&hid_cm108_driver);
}
static void hid_cm108_exit(void)
{
hid_unregister_driver(&hid_cm108_driver);
}
module_init(hid_cm108_init);
module_exit(hid_cm108_exit);
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
used This makefile
obj-m += cm108.o
and compile the module
make -C /lib/modules/`uname -r`/build/ M=`pwd` EXTRAVERSION="-generic" modules
sudo make -C /lib/modules/`uname -r`/build/ M=`pwd` EXTRAVERSION="-generic" modules_install
depmod -a
I had to modify the modules.order file so that my module would get queried before the generic hid linux module.
This modules make sure that the hidraw uses Interface 2.
Then I can use fopen to read and write to the GPIO pin of the CM108 chip.
BTW: when writing you need to write 5byte the 1st byte is used for the HID_OUTPUT_REPORT
Most hardware in Linux is accessible as a file. If the driver created a hardware node for it on the file-system, you're in luck. You will be able to write to it using regular file routines. Otherwise, you may need to do some assembly magic, which may require you to write a kernel module to do it.
Here is a complete example of how to write to the CM108/CM119 GPIO pins on Linux.
https://github.com/wb2osz/direwolf/blob/dev/cm108.c
You don't need to run as root or write your own device driver.
I have the opposite problem. I'm trying to figure out how to do the same thing on Windows.