Page 1 of 2
Report with MS Sql datasource with Asp.net adapter
Posted: Wed Apr 27, 2016 7:16 pm
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!
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Thu Apr 28, 2016 6:20 am
by HighAley
Hello.
You could find a sample site with connection to the available databases on
Github.
Thank you.
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Thu Apr 28, 2016 12:55 pm
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 ?
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Fri Apr 29, 2016 7:32 am
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.
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Fri Apr 29, 2016 2:13 pm
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!
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Mon May 02, 2016 12:51 pm
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.
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Mon May 02, 2016 1:46 pm
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 ?
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Mon May 02, 2016 2:09 pm
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:
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!
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Tue May 03, 2016 6:49 am
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.
Re: Report with MS Sql datasource with Asp.net adapter
Posted: Tue May 03, 2016 12:43 pm
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 ?