Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Crystal reports ActiveX - change DSN properties from code

(0) ShareShare
ReportReport
Posted on by 80

I am using following code to run crystal report in activex control of crystal report in dynamics ax. every thing is working fine when In crystal report the value of "Use DSN Default Properties" is set to False. But I want to change its value from coding. I am stucked how can i change it from code. It is giving me error. on this line.

IConnectionProperty = INameValuePairs.add("Use DSN Default Properties",False);

Error:

Method 'add' in COM object of class 'INameValuePairs' returned error code 0x80070057 (E_INVALIDARG) which means: One or more arguments are invalid.

My code starts here;

public void run()
{
Com comapp;
Com reporting;
Com IDatabase;
Com IDatabaseTable;
Com IDatabaseSingleTable;
Com INameValuePairs;
Com INameValuePairs2;
Com INameValuePairs3;
COM tc;
COM IConnectionProperty2;

Com IConnectionProperty;
Com ds;
COM DLL_Name;
str paramwhole;
str paramfilename;
str paramCond;
str ViewYesNo;
int ret;
str selectionFormula;
COMVariant variant;

DialogButton diagBut;
str strMessage;
str strTitle;
;

super();

variant = new COMvariant(COMVariantInOut::OUT,COMVariantType::VT_BOOL) ;
//paramwhole = this.args().parm("'{Employee.empcode}'='11752'");
paramwhole = this.args().parm();
//paramwhole = this.args().parm("{Employee.empcode}='11752'");
//paramwhole = this.args().parm("{?DateFrom}='01/01/2021';{?DateTo}='03/03/2021';{Employee.empcode}='11752'");

comapp = new COM("CrystalRuntime.Application.11");
ret = strfind(paramwhole,"|",2,strlen(paramwhole));

//paramfilename = "e:\\rptTimeSheet.rpt"; //substr(paramwhole,2,ret-2) ;
paramfilename = "e:\\Report10.rpt"; //substr(paramwhole,2,ret-2) ;
ViewYesNo = substr(paramwhole,1,1);
reporting = comapp.openreport(paramfilename);

reporting.discardsaveddata();


comapp.LogonServer("crdb_odbc.dll","tms","tacs", "sa", "mypassword");
breakpoint;

IDatabase =reporting.Database();

IDatabaseTable = IDatabase.Tables();
IDatabaseSingleTable = IDatabaseTable.Item(1);
INameValuePairs = IDatabaseSingleTable.connectionproperties();
IConnectionProperty = INameValuePairs.add("Use DSN Default Properties",False);


paramcond = substr(paramwhole,ret+1,strlen(paramwhole));

reporting.RecordSelectionFormula(paramCond);
reporting.readrecords();


if(ViewYesNo == 'N')
{
variant.boolean(false);
reporting.PrintOut(variant);
}
else
{
ActiveX.ReportSource(reporting);
ActiveX.width(600);
ActiveX.height(350);
ActiveX.DisplayToolbar(true);
ActiveX.DisplayGroupTree(false);

ActiveX.ViewReport();
ActiveX.Refresh();
}


}

  • ToddB Profile Picture
    on at
    RE: Crystal reports ActiveX - change DSN properties from code

    Hi mnaeembaigAX,

    Does the information in this older thread help?

    Calling Crystal Report from AX 2012 R2

    community.dynamics.com/.../calling-crystal-report-from-ax-2012-r2

  • mnaeembaigAX Profile Picture
    80 on at
    RE: Crystal reports ActiveX - change DSN properties from code

    I am using Dynamics AX 2012 R3 Cu11.

  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: Crystal reports ActiveX - change DSN properties from code

    I moved your question from the thread called Restore model stone between environment, then users override permission is back to original (blocked fields are unblocked), because your question has nothing to do with it.

    What is your version of AX?

    By the way, please always use Insert > Insert Code (in the rich-formatting view) to paste source code. Among other things, it preserves indentation, making code easier to read. Take a look:

    public void run()
    {
    	Com comapp;
    	Com reporting;
    	Com IDatabase;
    	Com IDatabaseTable;
    	Com IDatabaseSingleTable;
    	Com INameValuePairs;
    
    	Com IConnectionProperty;
    	str paramwhole;
    	str paramfilename;
    	str paramCond;
    	str viewYesNo;
    	int ret;
    	COMVariant variant;
    
    	super();
    
    	variant = new COMvariant(COMVariantInOut::OUT,COMVariantType::VT_BOOL) ;
    	//paramwhole = this.args().parm("'{Employee.empcode}'='11752'");
    	paramwhole = this.args().parm();
    	//paramwhole = this.args().parm("{Employee.empcode}='11752'");
    	//paramwhole = this.args().parm("{?DateFrom}='01/01/2021';{?DateTo}='03/03/2021';{Employee.empcode}='11752'");
    
    	comapp = new COM("CrystalRuntime.Application.11");
    	ret = strfind(paramwhole,"|",2,strlen(paramwhole));
    
    	//paramfilename = "e:\\rptTimeSheet.rpt"; //substr(paramwhole,2,ret-2) ;
    	paramfilename = "e:\\Report10.rpt"; //substr(paramwhole,2,ret-2) ;
    	viewYesNo = substr(paramwhole,1,1);
    	reporting = comapp.openreport(paramfilename);
    
    	reporting.discardsaveddata();
    
    
    	comapp.LogonServer("crdb_odbc.dll","tms","tacs", "sa", "mypassword");
    	breakpoint;
    
    	IDatabase =reporting.Database();
    
    	IDatabaseTable = IDatabase.Tables();
    	IDatabaseSingleTable = IDatabaseTable.Item(1);
    	INameValuePairs = IDatabaseSingleTable.connectionproperties();
    	IConnectionProperty = INameValuePairs.add("Use DSN Default Properties",False);
    
    	paramcond = substr(paramwhole,ret 1,strlen(paramwhole));
    
    	reporting.RecordSelectionFormula(paramCond);
    	reporting.readrecords();
    
    	if (viewYesNo == 'N')
    	{
    		variant.boolean(false);
    		reporting.PrintOut(variant);
    	}
    	else
    	{
    		ActiveX.ReportSource(reporting);
    		ActiveX.width(600);
    		ActiveX.height(350);
    		ActiveX.DisplayToolbar(true);
    		ActiveX.DisplayGroupTree(false);
    
    		ActiveX.ViewReport();
    		ActiveX.Refresh();
    	}
    }

    I also removed a bunch of unused variables.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans