Report with MS Sql datasource with Asp.net adapter

Stimulsoft Reports.JS discussion
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Hi.

The docs about this part could improve much more. Basically talks about StiOptions.WebServer.url config and nothing more. I created a report with windows designer, that has a string connection to my sql server. The preview data works normally.

Which are they my next steps ? How can i load this report from javascript?

Code: Select all

var report = new Stimulsoft.Report.StiReport();
report.loadFile("js/report.mrt");
StiOptions.WebServer.url = "http://myasptnetapp:9615";
???

Thanks!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Report with MS Sql datasource with Asp.net adapter

Post by HighAley »

Hello.

You could find a sample site with connection to the available databases on Github.

Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Hi HighAley.

Looking "02. Connect to databases" example, we have this:

Code: Select all

StiOptions.WebServer.url = "handler.aspx";
var options = new Stimulsoft.Designer.StiDesignerOptions();
options.appearance.fullScreenMode = true;
var designer = new Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
designer.renderHtml("content");
This is ok, the request to my server occur normally. Now looking adapter code:

Code: Select all

var command = (CommandJson)new DataContractJsonSerializer(typeof(CommandJson)).ReadObject(HttpContext.Current.Request.InputStream);
Result result = new Result();
if (command.Database == "MySQL") result = MySQLAdapter.Process(command);
if (command.Database == "Firebird") result = FirebirdAdapter.Process(command);
if (command.Database == "MS SQL") result = MSSQLAdapter.Process(command);
if (command.Database == "PostgreSQL") result = PostgreSQLAdapter.Process(command);

var serializer = new DataContractJsonSerializer(typeof(Result));

serializer.WriteObject(HttpContext.Current.Response.OutputStream, result);
HttpContext.Current.Response.Headers.Add("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.Headers.Add("Cache-Control", "no-cache");

HttpContext.Current.Response.OutputStream.Flush();
HttpContext.Current.Response.End();
Where is the report's reference I want to load ?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Report with MS Sql datasource with Asp.net adapter

Post by HighAley »

Hello.

If you need to load and show the report in the Viewer, you should do it instead of loading the designer in our sample.

Instead this code:

Code: Select all

var options = new Stimulsoft.Designer.StiDesignerOptions();
options.appearance.fullScreenMode = true;
var designer = new Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
designer.renderHtml("content");
use this:

Code: Select all

var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
var report = new Stimulsoft.Report.StiReport();
report.loadFile("js/report.mrt");
viewer.report = report;
Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Hi HighAley.

But my report has MS Sql datasource and shows this dialog error: The database type is not supported by pure JavaScript. Please read documentation.

I just want to load my report from javascript with data that are stored in my sql database.

How can i achieve this ?


Thanks for attention!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Report with MS Sql datasource with Asp.net adapter

Post by HighAley »

Hello.

It seems that you did not specify the StiOptions.WebServer.url.
You should set there the path to the data adapter.
Please, read the Programming Manual.

Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Thanks again HighAley!

Now the request works ok with this code:

Code: Select all

StiOptions.WebServer.url = "http://localhost:8815/Handler";
var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
var report = new Stimulsoft.Report.StiReport();
report.loadFile("js/database1.mrt");
viewer.report = report;
viewer.renderHtml("report_designer");
But the response of request show me this error : You can not convert a type 'System.Int32' object in 'System.String' type.
I specified correctly the type of my fields on my ms datasource. I have one int field (my primary key), one datatime and 2 string. This message don´t help me to find the problem.

What i´m doing wrong ?
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Looking more deeply at MYSQLAdapter.cs:
on this line had already one error message:

Code: Select all

connection = new SqlConnection(command.ConnectionString);
At connection object: ServerVersion = 'connection.ServerVersion' threw an exception of type 'System.InvalidOperationException'
base = {"Invalid operation. The connection is closed."}
Although it does not fall in the catch block

Code: Select all

 try
  {
       connection = new SqlConnection(command.ConnectionString);
       connection.Open();
       return OnConnect();
  }
  catch (Exception e)
  {     
       return OnError(e.Message);
  }
Looking this code at handler.aspx.cs:

Code: Select all

Result result = new Result();
The contents of the result object is precisely the error that was presented to the client:

Code: Select all

Columns = null
Notice = "Can not convert a type 'System.Int32' object to type 'System.String'."
Rows = null
Success = false
What i´m doing wrong ?

Thanks!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Report with MS Sql datasource with Asp.net adapter

Post by HighAley »

Hello.

Please, check your connection string.
Do you use the right connection string and do you have access to the data base from the server?

Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Report with MS Sql datasource with Asp.net adapter

Post by felipemoreira »

Hi HighAley.

Yes, the connection string is correct.

The only difference from example, is that the js code is inside of simple html page from another project, not inside of default.aspx page.

It could be a problem ?
Post Reply