Creating SessionMgr instance for crystal reports throws error - c#

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;

Related

Cannot connect to hana database on-premise using 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.

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);
}
}

c# Rotativa issue in production server using user built template pdf generation

i am developing a enterprise app in c# .net. There are many pdf documents generated in the system. I use Rotativa for pdf handling. There is one pdf which uses user created template in the system. System fetches data from the system and replaces the template variables with the dynamic values from server and downloads the pdf. This particular pdf is working fine in my local and development server, but fails in the production server. Will be glad if somebody could help. i have attached the error and the code. please have a look.
public ActionResult GenerateRedemptionLetterGift(int id, int templateId)
{
try
{
int RedTempId = templateId; //Convert.ToInt32(Request.QueryString["templateId"]);
int type = 2;
RedemptionCode RedemptionObj = new RedemptionCode();
RedemptionObj = BlObj.GetRedemptionDetail(id);
return new Rotativa.MVC.ActionAsPdf("ReturnTemplate", new { id, RedTempId, type }) { FileName = "Redemption_Letter_" + RedemptionObj.Id.ToString() + ".pdf" };
}
catch (Exception ex)
{
throw new Exception("Main Method", ex);
}
}
here i call a function ReturnTemplate as ActionAsPdf where all the data is fetched and replaced in the user created template.
public ActionResult ReturnTemplate(int id, int RedTempId, int type)
{
try
{
RedemptionTemplateBO RedTemp = new RedemptionTemplateBO();
RedTemp = BlObj.GetRedemptionTemplateForEdit(RedTempId);
Hashtable TempStrings = new Hashtable();
if (type == 1)
{
TempStrings = GenerateRedemptionHashTable(id);
}
else if (type == 2)
{
TempStrings = GenerateRedemptionHashTableGift(id);
}
StringBuilder builder = new StringBuilder();
builder.Append("<html><head><title>Redemption Letter</title></head><body><style> #font-face {font-family: myFirstFont;src: url(~/fonts/Roboto-Regular.ttf);} p{font-family: 'Roboto', sans-serif;color: #3e3e3e;font-size: 15px;font-weight: 400;margin-bottom: 10px}</style>");
builder.Append(RedTemp.TemplateContent);
builder.Append("</body></html>");
foreach (string key in TempStrings.Keys)
{
builder.Replace("[" + key + "]", (string)TempStrings[key]);
}
return Content(builder.ToString());
}
catch( Exception ex)
{
throw new Exception("Return Template", ex);
}
}
I have checked in the local using a break point, if i am getting the correct data in the string for returning in the second method. Its coming fine.
Its running fine in both local and development server. I am getting the expected pdf.
But when i run it in production. i am running into an error, and it doesnt seem to be hitting the try catch block also.
Server Error in '/' Application.
Error: Failed loading page http://app.com/Redemption/ReturnTemplate/185?RedTempId=3&type=2 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: RemoteHostClosedError
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Error: Failed loading page http://app.com/Redemption/ReturnTemplate/185?RedTempId=3&type=2 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: RemoteHostClosedError
This is the last few stack trace
Rotativa.Core.WkhtmltopdfDriver.Convert(DriverOptions options, String html) +793
Rotativa.MVC.AsPdfResultBase.CallTheDriver(ControllerContext context) +27
Rotativa.MVC.AsPdfResultBase.BuildPdf(ControllerContext context) +203
Rotativa.MVC.AsPdfResultBase.ExecuteResult(ControllerContext context) +27
WkhtmltopdfDriver takes too long to respond from production server.
Could it be due to some outgoing calls in Rotativa server. But still my other pdf generations work fine with rotativa in the production server.
We had a similar but different error: Failed loading page:...HostNotFoundError
Basically, rotativa was trying to resolve the domain name from within the intranet, but this particular network does not allow you to access their own public facing sites using its bound domain name. Switching to .UrlAsAPdf and using the intranet IP address, fixed this.
Also test the PDF view/ page locally first, to see that it is doing what you want.

Cannot get LDAP connection working - always "Unknown error"

I'm researching what I need to build an Active Directory search tool which ultimately will be used in a C# ASP.NET web app.
I know very little about AD (and don't particularly want to know any more than necessary) so I've asked our tech ops to set up a dummy instance on a server. This they've done giving it the domain dummy.local
I now need to work out my LDAP connection string. Here I'm completely stuck. I'm using a user account which is a member of Domain Admins. After loads of hunting round the web I've tried all sorts of things to work out the various components of the LDAP connection string. For example, if I run the following in cmd.exe for that domain admin user on the server...
dsquery user -samid "username" | dsget user -memberof -expand
...this gives me the following information:
"CN=Domain Admins,CN=Users,DC=dummy,DC=local"
"CN=Remote Desktop Users,CN=Builtin,DC=dummy,DC=local"
"CN=Users,CN=Builtin,DC=dummy,DC=local"
"CN=Administrators,CN=Builtin,DC=dummy,DC=local"
"CN=Domain Users,CN=Users,DC=dummy,DC=local"
"CN=Denied RODC Password Replication Group,CN=Users,DC=dummy,DC=local"
I've also run the following in a C# console app...
using (var context = new PrincipalContext(ContextType.Domain))
using (var comp = ComputerPrincipal.FindByIdentity(context, Environment.MachineName))
{
Console.WriteLine(String.Join(",", comp.DistinguishedName.Split(',').SkipWhile(s => !s.StartsWith("OU=")).ToArray()));
}
...and this gives me the following:
OU=Domain Controllers,DC=dummy,DC=local
I thought I therefore had all the properties I needed to build my LDAP connection string. I ended up with this:
LDAP://COMSECWEBDEV.dummy.local/ou=Domain Controllers,/cn=Domain Admins,/cn=Users,/dc=dummy,/dc=local
I've tried using this connection string, with the username and password of the domain admin which I know is correct, but everything I try always gives me the same error:
System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
Since this error gives me no detail I have no idea what I'm doing wrong. I'm sure I'm just not getting the connection string right, but I've no idea how to work out the correct string.
For completeness, here is the console code which I'm testing with:
static void Main(string[] args)
{
var connString = ConfigurationSettings.AppSettings["lc"];
var username = ConfigurationSettings.AppSettings["lu"];
var password = ConfigurationSettings.AppSettings["lpw"];
using (DirectoryEntry de = new DirectoryEntry(connString, username, password))
{
DirectorySearcher search = new DirectorySearcher(de);
search.PageSize = 1001;// To Pull up more than 100 records.
DirectorySearcher directorySearcher = new DirectorySearcher(de);
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username);
directorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");
try
{
var result = directorySearcher.FindOne();
var found = false;
if (result != null)
{
if (result.Properties["msRTCSIP-PrimaryUserAddress"] != null)
{
found = true;
Console.WriteLine("Found: " + result.Properties["msRTCSIP-PrimaryUserAddress"][0]);
}
}
if (!found)
{
Console.WriteLine("Sad face");
}
}
catch (Exception x)
{
Console.WriteLine(x.Message);
}
Console.WriteLine("------------");
}
}
I was trying to figure out how to properly format a LDAP connection string last week, and found this entry over on serverfault:
How can I figure out my LDAP connection string?
I noticed you had a "/" between each OU or DC entry - I didn't include those in mine, and I don't see them included in the above example either.
I'm far from an expert (obviously) but just figured I would throw it out there.

'System.Runtime.InteropServices.COMException' error on indesign interop

Im trying make automated page design with Adobe InDesign CC.
this is my code in C# :
public class HomeController : Controller
{
public ActionResult Index()
{
object missing = Type.Missing;
Type type = Type.GetTypeFromProgID("InDesign.Application");
if (type == null)
{
throw new Exception("Adobe InDesign CC is not installed");
}
_Application app = (_Application)Activator.CreateInstance(type);
Document document = (Document)app.Documents.Add(true, missing);
Page page = (Page)document.Pages[1];
TextFrame textFrame = page.TextFrames.Add(missing,
idLocationOptions.idUnknown, missing);
textFrame.GeometricBounds = new string[] { "6p", "6p", "24p", "24p" };
textFrame.Contents = "Hello from .Net!";
return View();
}
now when i run it gives this error to me :
An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code
Additional information: Retrieving the COM class factory for component with CLSID {FB6F0F4B-0467-4F63-88EC-3960B8E1B3EE} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
error happens in line :
_Application app = (_Application)Activator.CreateInstance(type);
this is the screenshot :
also , when i run this code , Adobe Indesign getting opened but do nothing happend until error shows up.

Categories