Connect Sap B1 hana with C# Application using DI API - c#

I am Trying to Connect MY Sap B1 HANA on C# Web Based Application using DI API but my connection is giving me error. Here is Error Screenshot Failed to Connect SLD,make Sure Your SLD Server is Available and Connected. Any Relevant Help would be Appreciated.
try{
oCompany.CompanyDB = "***";
oCompany.Server = "***";
oCompany.LicenseServer = "***:30015";
oCompany.SLDServer = "***:40000"; //
oCompany.DbUserName = "****"; //
oCompany.DbPassword = "****"; //
oCompany.UserName = "****"; //
oCompany.Password = "****"; //
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = false;
int res = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
{
value1 = errMsg;
return errMsg;
}
else {
value1 = "Succes Connection To Sap B1 Hana";
return value1;
}

You must include the port number in the server. Usually, the port number is 30015.

you can also use below mention code.
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany();

The following connection code should get you a step further:
// The actual database host
// With HANA the single-tenancy port 30015 needs to be provided together with the host (not so with MSSQL)
// When using HANA multi-tenancy the instance is prefixed and the port changed: INSTANCE#DB-HOST:30013
// OR the correct instance port needs to be provided, eg. DB-HOST:30017
sboCompany.Server = "DB-HOST:30015";
// The company database/schema name
// With MSSQL the instance is provided here like: INSTANCE\DB_NAME
sboCompany.CompanyDB = "SCHEMA";
// SLDServer is the new LicenseServer, don't forget the port with HANA
// Be aware: use either hostname or IP of SLD everywhere
sboCompany.SLDServer = "SLD-HOST:40000";
// Hell knows why the version needs to be provided for MSSQL...
sboCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
// DB credentials when using MSSQL authentication or HANA
sboCompany.UseTrusted = false;
sboCompany.DbUserName = "SYSTEM";
sboCompany.DbPassword = "password";
// SBO credentials
sboCompany.UserName = "manager";
sboCompany.Password = "password";
The next problems might be missing or wrong HANA drivers... your journey just began ;-)

Related

How can I connect to IBM MQ using SSL connection by C# IBMXMSDotnetClient

I am currently able to connect to the IBM MQ server based on jndi binding file with the following c# code
InitialContext ic = null;
IConnectionFactory confac = null;
IConnection conn = null;
ISession sess = null;
IMessageConsumer cons = null;
IDestination dest = null;
try
{
System.Collections.Hashtable env = new System.Collections.Hashtable();
// Set the URL or PATH where the bindings file is located
env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
// Initialize the context
ic = new InitialContext(env);
// Lookup for the connection factory name
confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
// Create connection using the details from connection factory
conn = (IConnection)confac.CreateConnection();
// Create an auto ack session
sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Lookup for the destination
dest = (IDestination)ic.Lookup("myqueue");
// ... rest of the code - create consumer or producer
}
catch (XMSException xmsE)
{
// Handle exception
}
However, when the SSL enabled in the IBM MQ Server, it fails to connect. Tried setting different properties (like setting XMSC.IC_PROVIDER_URL to the keystores directory/.jp12 file), but does not seem working.
Exception I got:
IBM.XMS.XMSException: 'CWSMQ0006E: An exception was received during the call to the method ConnectionFactory.CreateConnection: CompCode: 2, Reason: 2059.
I also cannot find any sample code on the official site on how this is working.
Any idea or sample code on this (not necessary in great details, at least, give me some ideas how what I need to set)?

How can I connect to IBM MQ using JNDI in c#?

I am currently able to connect to a IBM MQ using IBMXMSDotnetClient by specifying the connection properties directly in the c# code like below.
XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connFactory = factory.CreateConnectionFactory();
connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
connFactory.SetStringProperty(XMSC.WMQ_CHANNEL, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "xxx");
But in Java, it seems that it can be done by JNDI bindings file.
From what I can see, it looks like that JNDI is something like TNS file (which specifies the connection details such host, port, SID, etc.) used by the client to connect to server in Oracle. Is my understanding correct?
If it is the case, is it possible to connect to the IBM MQ by JNDI bindings files using IBMXMSDotnetClient? All examples I can find is to set the connection properties (connFactory.SetXXXProperty) directly.
I have this snippet to create initial context and use it to create connection factory and sessions. Hope it will get you started.
InitialContext ic = null;
IConnectionFactory confac = null;
IConnection conn = null;
ISession sess = null;
IMessageConsumer cons = null;
IDestination dest = null;
try
{
System.Collections.Hashtable env = new System.Collections.Hashtable();
// Set the URL or PATH where the bindings file is located
env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
// Initialize the context
ic = new InitialContext(env);
// Lookup for the connection factory name
confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
// Create connection using the details from connection factory
conn = (IConnection)confac.CreateConnection();
// Create an auto ack session
sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Lookup for the destination
dest = (IDestination)ic.Lookup("myqueue");
// ... rest of the code - create consumer or producer
}
catch (XMSException xmsE)
{
// Handle exception
}

ChilkatDotNet2: connect to server SFTP

In my C# project I have included ChilkatDotNet2.dll in order to connect to a SFTP server. For the moment, I have tried to implemt a simple connection method like the following:
Chilkat.Ftp2 F = null;
F = (Chilkat.Ftp2)new Chilkat.Ftp2();
F.Hostname = "sftp.domain.com";
F.Username = "username";
F.Password = "password";
F.Port = 22;
F.AuthTls = true;
if (!(F.Connect())) {
MainFrm.set_AlertMessage(F.ConnectFailReason);
}
and it always fails connecting and I always get the error 200 which means
Connected, but failed to receive greeting from FTP server.
according to Chilkat documentation.
What am I missing? I have tried to connect to a simple ftp server test (without SSL/TLS) and it connects correctly so I think I am missing something.
The credentials I was given are correct as I tried to connect to the SFTP server with Filezilla.
Thank you.
UPDATE
Chilkat.SFtp v_SFTP = null;
v_SFTP = (Chilkat.SFtp)new Chilkat.SFtp();
if (v_SFTP.Connect("sftp.domain.com", 22) {
if (v_SFTP.AuthenticatePw("username", "password")) {
IDVariant v_SUCCESS = null;
bool v_SUCCESS = v_SFTP.InitializeSftp();
}
}
else {
MainFrm.set_AlertMessage(v_SFTP.LastErrorText);
}
F = (Chilkat.Ftp2)new Chilkat.Ftp2();
Chilkat.Ftp2 is an FTP client. It supports the FTP protocol. SFTP is a completely different protocol which just happens to have a similar name.
If you want to connect to an SFTP server using Chilkat, look at Chilkat.SFtp.

How to issue SSH command

I am using C# with SSH.NET.
I want to issue a PWD command but could not find any documentation or help. I do not know how to use 'SshClient' class.
Update:
I also tried experimenting with SshClient class using the below code but it does nothing, neither any error nor any exception.
ConnectionInfo ConnNfo = new ConnectionInfo("FTPHost", 22, "FTPUser",
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod("FTPUser","FTPPass")
}
);
using (var ssh = new SshClient(ConnNfo))
{
ssh.Connect();
if (ssh.IsConnected)
{
string comm = "pwd";
using (var cmd = ssh.CreateCommand(comm))
{
var returned = cmd.Execute();
var output = cmd.Result;
var err = cmd.Error;
var stat = cmd.ExitStatus;
}
}
ssh.Disconnect();
}
Nothing happens. Neither an error nor an exception. On Visual Studio console, i get the below output.
*SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #152199'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server:
'ChannelFailureMessage': 'SSH_MSG_CHANNEL_FAILURE : #0'.*
At ssh.RunCommand method call the program goes in some sleep state (or waits for around 1 minute). sshCommand.Result and sshCommand.Error variables are empty.
Here's a quick example - one way to do it.
string host = "myhost";
string user = "root";
string pwd = "#secret#!"; // Don't use hardcoded plain-text passwords if possible - for demonstration only.
using (PasswordAuthenticationMethod auth = new PasswordAuthenticationMethod(user, pwd))
{
ConnectionInfo connection = new ConnectionInfo(host, user, auth);
using (var ssh = new SshClient(connection))
{
ssh.Connect();
SshCommand sshCommand = ssh.RunCommand("pwd");
Console.WriteLine("Command execution result: {0}", sshCommand.Result);
}
}
Note that if you specify an invalid command (e.g. "pwdxxxx"), you won't get an exception, but an error that will be stored in the SshCommand.Error string.
Note also that this uses SSH PasswordAuthentication, which may not be enabled in your SSH config.
Try looking into the documentation of SSH.NET:
SSH.NET at CodePlex
Code sample for executing a command (recommended)
Help file.CHM

Why i get ORA-12504 error in my connection string?

I'm beginner in oracle,want to connect oracle database with c# windows appliation
but why i try connect database i get this error:
my listener file is this:
MYLISTNER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-A5CFJSH)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_MYLISTNER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\BEHZAD-HUSH\product\11.2.0\dbhome_2)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\app\BEHZAD-HUSH\product\11.2.0\dbhome_2\bin\oraclr11.dll")
)
)
ADR_BASE_MYLISTNER = C:\app\BEHZAD-HUSH
and my tnsnames file is:
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
What happen?How can i solve that?thanks.
my tns ping is:
TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 02-NOV-2015 15:42:22
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
C:\app\BEHZAD-HUSH\product\11.2.0\dbhome_2\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))) (CONNECT_DATA = (SID = CLRExtProc) (PRESENTATION = RO)))
TNS-12541: TNS:no listener
Server name should be from TNS (ORACLR_CONNECTION_DATA), not localhost.
EDIT:
TNS-12541: TNS:no listener
Check that tns listener is running.
CMD> lsnrctl
LSNRCTL> start
Before you start to develop application, you must first check database connection over tnsping/sqlplus. Only after you have successfully connected you can move forward.
If listener is curently runnig, you cant try to connect over tcp/ip, not over IPC (after changing tns connection string in tnsnames.ora) on this -
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = DESKTOP-A5CFJSH) (PORT = 1521))
(CONNECT_DATA = (SID = CLRExtProc))
)
TNS is a real double-edged sword. When it works, it works great, but if you don't have any control over the client machine where you are deploying an app, you may want to just skip it and connect directly.
Fortunately, Oracle came up with ezConnect, which dramatically simplifies connection strings. It's essentially:
server/port:service name (or SID)
By explicitly specifying the elements normally encapsulated in TNSNAMEs, you eliminate any chances that the target machine has a different definition for that TNS name or worse, no definition at all.
Or, if you use the Direct=true, you can still bypass TNSnames and explicitly spell out the server, port and service name:
String conString = String.Format("Direct=true;Server={0};" +
"Port={1};Service Name={2};User Id={3};Password={4};",
"myhost.foo.bar", 1521, "oraprod", "scott", "tiger");
or using the SID (I can never remember which works, so I try both):
String conString = String.Format("Direct=true;Server={0};" +
"Port={1};SID={2};User Id={3};Password={4};",
"myhost.foo.bar", 1521, "oraprod", "scott", "tiger");
and then:
OracleConnection conn = new OracleConnection(constring);
conn.Open();
(with appropriate error trapping, of course).
That was more info than you asked for, but the bottom line is when you are establishing the connection, I would use this as the "Server Name" in your dialog:
DESKTOP-A5CFJSH:1521/CLRExtProc

Categories

Resources