Cannot connect to hana database on-premise using C# - c#

I'm trying to follow this tutorial to connect my C# program to HANA Database On-Premise server using SAP DI API, but it does not work for me. I always got an error info like this;
Retrieving the COM class factory for component with CLSID {632F4591-AA62-4219-8FB6-22BCF5F60090} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
This is the code that I used;
private void btnConnection_Click(object sender, EventArgs e)
{
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
try
{
oCompany.CompanyDB = "DBSYS1";
oCompany.Server = "DBSYS1#192.168.xx.xxx";
oCompany.LicenseServer = "DBSYS1#192.168.xx.xxx:30015"; //IP Address of HANAsystem followed by Port number
oCompany.UserName = "username";
oCompany.Password = "password";
oCompany.DbServerType = BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = true;
int ret = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
{
MessageBox.Show(errMsg);
}
else
{
MessageBox.Show("Connected");
}
}
catch (Exception errMsg)
{
throw errMsg;
}
}
I have tried to find some solutions and I got this link.
It mentioned that the program platform target has to change to x86 or x64. But it still does not work for me.

Related

ISWiRelease Throwing COM Exception in Install Shield Automation

Iam trying to create an Automation in Install Shield,
But Whenever I try to create object of ISWiRelease it throws following exception.
Additional information: Retrieving the COM class factory for component
with CLSID {16C4628B-361F-4739-8D75-4E8FA8C4A348} failed due to the
following error: 80040154 Class not registered (Exception from
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I tried changing target platform to x86,Still Iam getting this exception.
Iam using Install Shield 2015 SP2.
DLL which I loaded is ISWiAuto22
Please help me to fix this issue.
Code:
public void BuildProject()
{
ISWiProductConfigs oProdConfigs;
ISWiProductConfig oProdConfig;
ISWiRelease oRelease = new ISWiRelease();
ISWiProject oISWiProj = new ISWiProject();
try
{
//Create IS object
oISWiProj.OpenProject(sProjectFileName, false);
//oISWiProj.ProductVersion = sBuildNumber;
oProdConfigs = oISWiProj.ISWiProductConfigs;
oProdConfig = oProdConfigs[oProdConfigs.Count];
oRelease = oProdConfig.ISWiReleases[1];
oRelease.ProgressIncrement += new __ISWiRelease_ProgressIncrementEventHandler(release_ProgressIncrement);
oRelease.StatusMessage += new __ISWiRelease_StatusMessageEventHandler(this.release_StatusMessages);
oRelease.BuildLocation = sBuildLocation;
oRelease.Build();
oISWiProj.SaveProject();
oISWiProj.CloseProject();
}
catch
{
//log("Build Failed...");
}
finally
{
oRelease.ProgressIncrement -= new __ISWiRelease_ProgressIncrementEventHandler(release_ProgressIncrement);
oRelease.StatusMessage -= new __ISWiRelease_StatusMessageEventHandler(this.release_StatusMessages);
}
}

windows service to read emails c#

I am trying to write a windows service which check my outlook inbox every minute.
I have the following code setup.
protected override void OnStart(string[] args)
{
timeDelay = new System.Timers.Timer(30000);
timeDelay = new System.Timers.Timer();
timeDelay.Elapsed += new System.Timers.ElapsedEventHandler(WorkProcess);
timeDelay.Enabled = true;
}
public void WorkProcess(object sender, System.Timers.ElapsedEventArgs e)
{
ReadMyEmail();
}
private void ReadMyEmail()
{
string content;
Application outlookApplication = null;
NameSpace outlookNamespace = null;
MAPIFolder inboxFolder = null;
Items mailItems = null;
try
{
outlookApplication = new Application(); // m getting the error here...
outlookNamespace = outlookApplication.GetNamespace("MAPI");
inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
mailItems = inboxFolder.Items;
foreach (MailItem item in mailItems)
{
if (item.UnRead)
......
...... all the code for reading emails.
}
}
}
I am getting the following error while i am trying to debug the application.
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
What am I doing wrong here.. I am just trying to read emails using a service.
This should not have been written as a Windows Service. For a "scheduled" application, you could have written this as a normal console application and setup the schedule to run it using Windows Scheduler. You can also set it up to run as you instead of as the system.

Creating SessionMgr instance for crystal reports throws error

I am using below code to connect to a SAP cms server to get the reports from it.
using CrystalDecisions.Enterprise;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string username = "user";
string password = "pwd";
string server = "srv_name";
string auth_type = "authType";
// logon
SessionMgr session_mgr = new SessionMgr();
EnterpriseSession boEnterpriseSession = session_mgr.Logon(username , password, server, auth_type);
//boInfoStore = (IInfoStore)boEnterpriseSession.getService("InfoStore");
//boInfoStore = (IInfoStore)boEnterpriseSession.GetService("InfoStore");
// get the serialized session
//string session_str = session.SerializedSession;
// pass the session to our custom bypass page on the CRS
}
}
But I am getting below mentioned error while executing following line of code : SessionMgr session_mgr = new SessionMgr();
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
CrystalDecisions.Enterprise.Framework.dll
Additional information: Retrieving the COM class factory for component
with CLSID {6670DE06-3F39-4C5D-9238-71FF984D2654} failed due to the
following error: 80040154 Class not registered (Exception from
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
According to nobugz's answer here
https://social.msdn.microsoft.com/Forums/vstudio/en-US/88a6ea68-f476-4231-822f-27fabe59f458/error-80040154-retreiving-com-class-factory?forum=vbgeneral
It is suggested that you check the keys in HKCR\CLSID for the GUID. if it is not in there, It may be in another folder(c:\windows\system32...).
The another way is to debug with Regmon.
"It shows you how your app uses the registry. Run it on yours and run it on the customer's and compare the two".
Try:
ISessionMgr sessionMgr = CrystalEnterprise.GetSessionMgr();
IEnterpriseSession enterpriseSession = sessionMgr.Logon("userName", "password", "cmsName", "secEnterprise");
string token = enterpriseSession.LogonTokenMgr.DefaultToken;

Remote OPC Connected but can't read

I am writing a custom OPC Client application in C#, enabling reading of data from a RSLinx Server.
First of, I wasn't able to connect to the RSLINX Opc Server remotely. Exception Access Denied kept occurring.
I then alteredthe DCOM Settings of MyComputer -> Com Security -> Access Permissions and Launch and Activation Permissions, enabled everything for the User 'Everyone'
This then allowed me to connect, but when It comes to read the server I get the following exception -
[System.Runtime.InteropServices.COMException] {"Exception from HRESULT: 0x80040202"} System.Runtime.InteropServices.COMException
I have scoured the web as much as I possibly can, and they all boil down to Dcom related issues. I have simply tried everything with the Dcom Settings. I have made sure the settings are enabled for both MyComputer and RSLinx server.
I am using two .dll files from OPCFoundation - opcNetApi.dll , opcNetApi.Com.dll
Here is my code, (It may be handy)
private void readplc()
{
Opc.URL url = new Opc.URL("opcda://48.5.0.05/RSLinx OPC Server");
Opc.Da.Server server = null;
OpcCom.Factory fact = new OpcCom.Factory();
server = new Opc.Da.Server(fact, null);
try
{
server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
}
catch (Exception exy)
{
MessageBox.Show(exy.Message);
}
// Create a group
Opc.Da.Subscription group;
Opc.Da.SubscriptionState groupState = new Opc.Da.SubscriptionState();
groupState.Name = "Group";
groupState.Active = true;
group = (Opc.Da.Subscription)server.CreateSubscription(groupState);
// add items to the group.
Opc.Da.Item[] items = new Opc.Da.Item[6];
items[0] = new Opc.Da.Item();
items[0].ItemName = "[ALARM]F20:9";
items[1] = new Opc.Da.Item();
items[1].ItemName = "[ALARM]F22:30";
items[2] = new Opc.Da.Item();
items[2].ItemName = "[ALARM]F22:6";
items[3] = new Opc.Da.Item();
items[3].ItemName = "[ALARM]F18:8";
items[4] = new Opc.Da.Item();
items[4].ItemName = "[ALARM]F22:32";
items[5] = new Opc.Da.Item();
items[5].ItemName = "[ALARM]F22:5";
items = group.AddItems(items);
try
{
group.DataChanged += new Opc.Da.DataChangedEventHandler(OnTransactionCompleted); // COM EXCEPTION THROWN HERE
Console.ReadLine();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Console.ReadKey();
}
}
private void OnTransactionCompleted(object group, object hReq, Opc.Da.ItemValueResult[] items)
{
for (int i = 0; i < items.GetLength(0); i++)
{
}
}
I know for certain that the code works as I have tried building the application connecting as a localhost on the PC I am trying to remote connect to, it reads the data happily.
Hopefully, someone will have some idea what is going on, I have spent over 12 hours in the last 4 working days trying to work it out!
This is working for me:
_opcServer = new Server(_comFactory, null) { Url = new Opc.URL("opcda://localhost/FactoryTalk Gateway") };
_opcServer.Connect();

virtual directory properties in c#

I did a quick search and got this link
From StackOverflow
I get this error message
"Unknown error (0x80005000)"
when it hits
bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN");
My requirement is to create a virtual directory and set AccessRead, IsolationMode, Scripts and Executables, ApplicationProtection to medium.
Got it to work, here is the code:
Note: I still couldn't get it to work on windows 7, it throws the same error and the message includes reference to System.InterOp... At the moment I don't care about getting it to work on windows 7, I deployed it on windows 2003, it works.
public void CreateVirtualDirectory(string virtualdirectory, string physicalpath)
{
try
{
///check if path exists
if (!Directory.Exists(physicalpath))
{
Log(string.Format(#"CreateVirtualDirectory; Path not found - {0}", physicalpath));
return;
}
DirectoryEntry parent = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/1/Root", Environment.MachineName));
foreach (System.DirectoryServices.DirectoryEntry v in parent.Children)
{
if (v.Name == virtualdirectory)
{
try
{
parent.Invoke("Delete", new string[] { v.SchemaClassName, virtualdirectory });
}
catch
{
}
}
}
DirectoryEntry newFolder = (DirectoryEntry)parent.Invoke("Create", "IIsWebVirtualDir", virtualdirectory);
newFolder.InvokeSet("Path", physicalpath);
newFolder.Invoke("AppCreate", false);
newFolder.InvokeSet("AppFriendlyName", virtualdirectory);
const int MEDIUM_POOL = 2;
newFolder.Properties["AccessRead"][0] = true;
newFolder.Properties["AccessExecute"][0] = true;
newFolder.Properties["AccessWrite"][0] = false;
newFolder.Properties["AccessScript"][0] = true;
newFolder.Properties["AuthNTLM"][0] = true;
newFolder.Properties["AppIsolated"].Clear();
newFolder.Properties["AppIsolated"].Add(MEDIUM_POOL);
newFolder.CommitChanges();
}
catch (Exception ex)
{
Log(string.Format(#"CreateVirtualDirectory '{0}' failed; {1}", virtualdirectory, ex.Message));
}
}
You're using DirectoryEntry to create websites which requires IIS Compat Mode to be installed/configured in IIS. That's compat mode for the IIS6 directory entry interfaces if you're on IIS7 or later.
If it's not installed, you'll get 80005000.
If you're on IIS7 or later (Windows Server 2008 or Vista and later), the newer (non-compat mode) approach is the new managed Microsoft.Web.Administration.
http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx

Categories