Skip to Content

Report from Visual studio code

Hi,

In my visual studio C# code I have created an API that creates a ReportDocument object. I am setting all the parameters, login credentials I am trying to login with a user who has access to 2 schemas. Both schemas have tables with same names. The report uses tables from schema2. When the code tries to generate memory stream of report I get "Field name is not known" error. This seems to be happening because the table the report is trying to use is from the schema1 which does not have all the fields the report is using. How can I make the report use particular schema. Is there a way I can set in my the .net code?

Here is my code snippet

ReportDocument rd = new ReportDocument();

var mappedPath = HttpContext.Current.Server.MapPath("~/Test");

rd.Load(Path.Combine(mappedPath ?? throw new InvalidOperationException(), "Test.rpt"));

ConnectionInfo connectioninfo = new ConnectionInfo();

connectioninfo.DatabaseName = "database1";

connectioninfo.UserID = "userabc";

connectioninfo.Password = "test123";

rd.DataSourceConnections[0].IntegratedSecurity = true;

Tables tables = rd.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)

{

TableLogOnInfo tableLogonInfo = table.LogOnInfo;

tableLogonInfo.ConnectionInfo = connectioninfo;

table.ApplyLogOnInfo(tableLogonInfo);

}

rd.SetDatabaseLogon(connectioninfo.UserID, connectioninfo.Password, connectioninfo.DatabaseName, connectioninfo.DatabaseName, true);

rd.VerifyDatabase();

byte[] getBytes;

MemoryStream ms = (MemoryStream)rd.ExportToStream(ExportFormatType.PortableDocFormat);

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 06 at 03:05 PM

    You would need to use ReplaceConnection() to update the connection info.

    Search for that and you should find examples.

    You can also use the sample app on the download WIKI here:

    https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.