SAP Netweaver. C++ Error:The memory cannot be read - c++

For my project, I need to test if the router string connects with SAP server successfully using SAP Netweaver 7.0. I have created a Console application in Visual studio 2017. I have given the connection parameters. But the application ends with an error: The memory cannot be read
#include <stdlib.h>
#include <stdio.h>
#include "stdafx.h"
#include "include/sapnwrfc.h"
void errorHandling(RFC_RC rc, RFC_ERROR_INFO*errorInfo, RFC_CONNECTION_HANDLE connection) {
printfU(cU("%s: %s\n"), errorInfo->key, errorInfo->message);
/* It's better to close the TCP/IP connection cleanly, than tojust let the backend get a "Connection reset by peer" error...*/
if (connection != NULL) RfcCloseConnection(connection, errorInfo);
exit(1);
}
int mainU(int argc, SAP_UC** argv)
{
RFC_RC rc = RFC_OK;
RFC_CONNECTION_PARAMETER loginParams[6];
RFC_ERROR_INFO errorInfo;
RFC_CONNECTION_HANDLE connection;
// -----------------------------------------------
// OPEN CONNECTION
// -----------------------------------------------
// Create logon parameter list
loginParams[0].name = cU("gwhost");
loginParams[0].value = cU("80.**.***.**");
loginParams[1].name = cU("sysnr");
loginParams[1].value = cU("00");
loginParams[2].name = cU("client");
loginParams[2].value = cU("800");
loginParams[3].name = cU("user");
loginParams[3].value = cU("jsar12");
loginParams[4].name = cU("lang");
loginParams[4].value = cU("EN");
loginParams[5].name = cU("****");
loginParams[5].value = cU("Abc");
// Open connection
connection = RfcOpenConnection(loginParams, 6, &errorInfo);
if (connection == NULL) errorHandling(rc, &errorInfo, NULL);
return 0;
}
Expected Result: Connection to the SAP Router

The solution for the above problem was in the settings of the Visual Studio. After a lot of searching and trying out a few tricks I have found the solution in the following link:
https://answers.sap.com/questions/12367200/netweaver-rfc-connector-error-logon.html
Summary:
On Linux and Windows, certain minimum releases of the C runtime are required to execute the programs. See SAP Notes 1021236 (for Linux) and 684106 (for Windows). The compiler and linker options needed to compile programs using the SAP NetWeaver RFC SDK are listed in SAP Note 1056696.
In addition, for Windows users using Microsoft Visual Studio, this is a description of how to set the Visual Studio project properties:
General section: Make sure the CharacterSet field is set to “Use Unicode Character Set.”
Debugging section: Under Environment, add something like Path=%Path%;nwrfcsdk\lib.
C/C++ section:
General: Add the nwrfcsdk\include directory under Additional Include Directories.
Preprocessor: Add the two preprocessor definitions SAPonNT and SAPwithUNICODE.
Code Generation: Choose “Multi-threaded DLL (/MD)” as the Runtime Library; selecting “Multi-threaded Debug DLL (/MDd)” may lead to strange problems.
Linker section:
General: Add the nwrfcsdk\lib directory under Additional Library Directories.
Input: Under Additional Dependencies, add libsapucum.lib, sapnwrfc.lib, and sapdecfICUlib.lib

Related

How can I deal with dll and lib files for connecting MariaDB to C++ Application?

I am trying to work on the project which is to connect MariaDB with C++ application.
I referred to the URL: https://mariadb.com/docs/clients/connector-cpp/#installing-mariadb-connector-c-via-msi-windows.
This URL is quite a good source to connect MariaDB with C++. However, it doesn't describe how to deal with the lib file and dll file.
When I installed the MariaDB connector/C++ via MSI, it gave me several files: conncpp.hpp, mariadbcpp.dll, mariadbcpp.lib, etc.
I tried to include mariadb/conncpp.hpp by setting the path C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include and I did same with the lib file.
Also, I went to the properties and set the linkers for the lib file.
Here is the code that I am planning to execute:
// Includes
#include <iostream>
#include <mariadb/conncpp.hpp>
// Main Process
int main(int argc, char** argv)
{
try
{
// Instantiate Driver
sql::Driver* driver = sql::mariadb::get_driver_instance();
// Configure Connection
// The URL or TCP connection string format is
// ``jdbc:mariadb://host:port/database``.
sql::SQLString url("jdbc:mariadb://192.0.2.1:3306/test");
// Use a properties map for the user name and password
sql::Properties properties({
{"user", "db_user"},
{"password", "db_user_password"}
});
// Establish Connection
// Use a smart pointer for extra safety
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
// Use Connection
// ...
// Close Connection
conn->close();
}
// Catch Exceptions
catch (sql::SQLException& e)
{
std::cerr << "Error Connecting to MariaDB Platform: "
<< e.what() << std::endl;
// Exit (Failed)
return 1;
}
// Exit (Success)
return 0;
}
But whenever I compile and execute the code, it says Unhandled exception(0x00007FF918058D25(mariadbcpp.dll), MariaDB_Connection.exe): 0xC0000005:Access violation reading location 0xFFFFFFFFFFFFFFFF at the line of
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));.
Could you tell me how to solve this problem?
You've hit the deficiency in the C++ connector API. Or call it a bug. It's Windows specific. Debug and release versions of STL objects may have different layout.
Switching build to release configuration should help. But some issues are still possible depending on VS version used. As a workaround you could also try to use other connect method, i.e.
std::unique_ptr<sql::Connection> conn(driver->connect(url, "db_user", "db_user_password"));
since it doesn't rely on Properties map, that causes the issue here.

Exception running Embarcadero project with libssh2

I face the following problem:
In Embarcadero project (either exe or dll) there is an exception when I call the libssh2_session_handshake() that establishes and ssh communication between 2 hosts.
I have built an .exe in Embarcadero RAD XE5 C++ (the same occurs if I build dll).
The project that creates this .exe, has linked statically the libssh2.lib library.
When trying to run the exe it loads dynamically the libssh2.dll.
The libssh2.lib and the libssh2.dll are built with Visual Studio. I have used various versions of them. The last one built the last code of libssh2 from git hub, with Visual Studio 2015.
From my job it is required these files to be incorporated to Embarcadero project.
In order the libssh2.lib file to be workable in Embarcadero I run the coff2omf.exe tool found in Embarcadero, that converts a .lib from Visual Studio to compatible to embarcadero.
When the code in Embarcadero project calls the libssh2_session_handshake, it constantly raises an exception:
"Access violation at address 00000000. Read of address 00000000".
I follow the example https://www.libssh2.org/examples/scp.html, which shows how to send a file to an sftp server, having first created an ssh conection.
Could anyone help to fix that? Do you have any idea what may cause it.
Thank you for you time.
Below I give a part of my code.
rc = libssh2_init(0);
ShowMessage("rc = " + IntToStr(rc));
if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
ShowMessage(AnsiString().sprintf("libssh2 initialization failed (%d)",rc));
return 1;
}
sock = socket(AF_INET, SOCK_STREAM, 0);
//Connect to Remote Host
//Prior that the ip of the remote host has been defined (sin)...
if(connect(sock, (struct sockaddr*)(&sin),
sizeof(struct sockaddr_in)) != 0) {
int wsaerr = WSAGetLastError();
ShowMessage("Failed to connect " + IntToStr(wsaerr));
//return -1;
}
try{
rc = libssh2_session_handshake(session, sock);
ShowMessage("libssh2_session_handshake rc: " + IntToStr(rc));
if(rc) {
ShowMessage("Failure establishing SSH session: " + IntToStr(rc));
//return -1;
}
}
catch(Exception &e){
ShowMessage("exception raised " + e.Message());
}
Usually in Embarcadero c++ Builder when you have error messages like
"Access violation at address 00000000. Read of address 00000000"
you should check to see if you have instantiated correctly your classes or third-party classes. Your program searched for your pointer for example, it can not find it, and then it goes to address 0000000.
in example
class MyAgent{
public: MyAgent::MyAgent()=default;
}
Then in your code
MyAgent *ptMyAgent = new MyAgent();
IF you had
MyAgent *ptMyAgent; // accepted on build but produces errors on run time.
It won't complain when building but will throw an error like the access violation at the top at runtime.

The way to start Microsoft Edge from C++ in Windows 10 does not work in Windows Server 2016

The following file test.cc is to launch Microsoft Edge with specific URL:
#include <Windows.h>
int main()
{
SHELLEXECUTEINFOW sei = { sizeof sei };
sei.lpVerb = L"open";
sei.lpFile = L"microsoft-edge:http://www.stackoverflow.com";
ShellExecuteExW(&sei);
}
Compile with:
cl test.cc /link shell32.lib
It works in Windows 10 (Edge opened to specific URL), but in Windows Server 2016 this program pops up an error window:
Title: microsoft-edge:http://www.stackoverflow.com
Content: This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.
I checked "Default Programs" in control panel and already chose "Set this program as default" in Microsoft Edge page.

Visual Studio 2012 : Oracle Database program using VC++ (MFC) & Oracle OCCI Library

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.

OCCI app crashes when running in debug mode in Visual Studio 2005

I'm attempting to get a development environment up and running for developing applications with Oracle C++ Call Interface (OCCI) in Visual Studio 2005.
My system specs are:
OS: Windows 7, 64-bit
Oracle: 11g release 11.2.0.2, 32-bit
Instant Client: BasicLite and SDK version 11.2.0.4 32-bit
Visual Studio 2005 Professional Edition version 8.0 with 32-bit tools enabled
I've followed this guide by Mark Williams and I got the example running but only in release mode. When I switch to debug mode the app will build, but when I run it I get the following error:
Problem signature:
Problem Event Name: APPCRASH
Application Name: OCCITest.exe
Application Version: 0.0.0.0
Application Timestamp: 53f5dfdd
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.18229
The small example program that triggers this error is:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
env = Environment::createEnvironment(Environment::DEFAULT);
try
{
con = env->createConnection(user, passwd, db);
}
catch (SQLException& ex)
{
cout << ex.getMessage();
exit(EXIT_FAILURE);
}
}
Employees::~Employees()
{
env->terminateConnection (con);
Environment::terminateEnvironment (env);
}
If I remove all calls to OCCI functionality the application doesn’t crash. That is, this program runs error-free:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
cout<<"Look at me, I'm running"<<endl;
}
Employees::~Employees()
{}
In the guide Mark mentions that when running in debug mode, the linker should use the library file oraocci11d.lib. However, this file is not included in the Instant Client SDK version 11.2.0.4, so I’m using the input file oraocci11.lib for both the release and debug version.
I'm running out of ideas about how to proceed in solving this problem, and I would greatly appreciate any and all help.
If the Oracle DLL receives and/or passes objects such as std::string or any other object that either:
Manipulates the heap in any way, or
The objects could have differing internals between app and DLL,
then you have no choice but to use the correct library to link with. Otherwise you wind up with binary or heap incompatible objects being passed, which leads to what you're seeing now.
See here: http://docs.oracle.com/cd/E11882_01/appdev.112/e10764/install.htm#CBHGBBJI
The link above mentions both the debug import library and debug version of the DLL. Also this is stated at the link:
Applications that link to MSVCRTD.DLL, a debug version of Microsoft C-Runtime, /MDd compiler flag, should link with these specific OCCI libraries: oraocci11d.lib and oraocci11d.dll.
Since it took me quite some time to get the debug environment working I figured I'd answer my own question now that I did.
I got a variety of errors throughout the ordeal, but the error that I got most stuck on was an error saying:
'The application was unable to start correctly (0xc0150002).
Click OK to close the application.'
Also, I used http://www.dependencywalker.com which repeatedly told me that either oraocci11d.dll or a the following list of dll's could not be found.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
However, what was really missing was for the executable to be able to find oci.dll. I'm just mentioning the errors in case someone else runs into these.
Here is what was needed to make it work:
First of all, the Instant Client does not contain the oraocci11d.lib or oraocci11d.dll, so it is necessary to install the full Oracle Client.
Next, the following must be added to the PATH:
C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
C:\Program Files\Oracle\11.2.0\BIN
In Visual Studio, select Tools -> Options, unfold 'Projects and Solutions' and select VC++ Directories. In 'Show directories for' under:
Include Files add C:\Program Files\Oracle\11.2.0\OCI\include
Library files add C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
In the property page for your project under Configuration Properties -> Linker select Input and under Additional Dependencies add oraocci11d.lib (or oraocci11.lib for release mode). Then select debug/release mode in the Configuration Manager
I have a related problem in that I am successfully using oraocci12d.dll/msvcr100d.dll, but this in turn is using oci.dll/msvcr100.dll. ie, oci.dll is not using the debug version of msvcr100.
My program seems to run okay, but any memory leak reporting disappears on exit.