Can`t register Sql Connection

Stimulsoft Reports.WEB discussion
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Can`t register Sql Connection

Post by Makarenya »

I'm using following code to register sql connection data source in report, and then design it:

Code: Select all

            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            StiReport report = new StiReport();
            report.RegData("azure", connection);
            StiWebDesigner1.Design(report);
But designer show me empty dictionary (only system variables and functions present, and no sql connections).

this is a web reports behavour.
Same code in windows form application (last line changed to report.Design();) works perfect, and show "Connections" Dictionary with "azure" item.

yes, of cource, i can use following code:

Code: Select all

report.Dictionary.Databases.Add(new StiSqlDatabase("azure", connectionString));
and this code works perfect, but I must provide design functinality to many users, and i must provide database connection to them, but i can`t give them database connection string with hostname, login and password, this is a security fail...
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Can`t register Sql Connection

Post by Alex K. »

Hello,

You can register the DataSet with help RegData() method, not all connection. Please try to get the necessary tables from your database in DataSet and then pass it to report.
example:

Code: Select all

DataSet dataForReport = new DataSet("azure");
using (SqlConnection connection = new SqlConnection("ConnectionString"))
{
    SqlDataAdapter dataCategories = new SqlDataAdapter("select * from Categories", connection);
    DataTable dataTableCategories = new DataTable();
    dataCategories.Fill(dataTableCategories);
    dataForReport.Tables.Add(dataTableCategories);
    ....
}
report.RegData("azure", dataForReport);
...
Thank you.
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Re: Can`t register Sql Connection

Post by Makarenya »

I see two problems with this solution:
- Users can't use SQL in report. In my previous report solution, some reports had been created on very complex sql queries, that uses cursors and other strange things.
- Working with reports by ajax produces many queries, and every query fills dataset. Web page don't know, what data is necessary for report, and what not. For very very tiny database this may not be a trouble. But for big database, this solution is a big trouble.
So, i need another solution.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Can`t register Sql Connection

Post by Alex K. »

Hello,

You can create your own method in which you will get the all necessary tables and pass it to the report.
Example:

Code: Select all

SqlConnection conn = new SqlConnection(@"Data Source=ALEKSEYPC\SE2012;Initial Catalog=Northwind;Integrated Security=True");
conn.Open();
DataTable tables = conn.GetSchema("Tables");
DataSet ds = new DataSet("DatatablesForReport");

foreach (DataRow row in tables.Rows)
{
    string selectQuery = "select * from [" + row["TABLE_NAME"].ToString() + "]";
    SqlDataAdapter dataCategories = new SqlDataAdapter(selectQuery, conn);
    DataTable dataTable = new DataTable(row["TABLE_NAME"].ToString());
    dataCategories.Fill(dataTable);
    ds.Tables.Add(dataTable);
}
report.RegData(ds);
Thank you.
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Re: Can`t register Sql Connection

Post by Makarenya »

My knowledge of English is poor.
So I did not make myself very clear. I'll try to google translate.
The fact that I have to provide users with an interface with which they can build any report, based on the available database (containing more than one billion records). I can not make the specialized own method, as different reports, each of which operates its own data, and I can not know - what exactly which report data operates as a report is created not me. At the same time I can not give users the database password. Yes, even her address I do not want them to report. In addition, it would be nice if users could make SQL queries directly from the report designer, since reports are not trivial.

When I made this decision on the Stimulsoft Reports.Net, everything was fine with the ability to provide a database connection through RegData.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Can`t register Sql Connection

Post by Alex K. »

Hello,

As alternative, you can pass the connection to database to the report and hide or deny access it for users. In this case user will be can create a new queries or modify the current queries.

Code: Select all

StiOptions.Designer.HideConnectionString = true;
report.Dictionary.Restrictions.Add("ConnectionName", StiDataType.Database, StiRestrictionTypes.DenyShow);
report.Dictionary.Restrictions.Add("ConnectionName", StiDataType.Database, StiRestrictionTypes.DenyEdit);
Also you can deny access to the datasources:

Code: Select all

report.Dictionary.Restrictions.Add("DataSourceName", StiDataType.DataSource, StiRestrictionTypes.DenyEdit);
Thank you.
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Re: Can`t register Sql Connection

Post by Makarenya »

I do not know why, but this method does not work.

Code: Select all

            StiReport report = new StiReport();
            report.Dictionary.Databases.Add(new StiSqlDatabase("azure", connectionString));
            StiOptions.Designer.HideConnectionString = true;
            report.Dictionary.Restrictions.Add("azure", StiDataType.Database, StiRestrictionTypes.DenyShow);
            report.Dictionary.Restrictions.Add("azure", StiDataType.Database, StiRestrictionTypes.DenyEdit);
            StiWebDesigner1.Design(report);
And I still can see and edit the properties of the connection string.

And then the main question is the connection establised from the client side? That is, the base climbs browser on the client side rather than the asp script?

If so, then you do not think it's a hole the size of Safety when commercials in the river gateway.
And do you have any desire to correct this situation in the next version. There ajax, which can transfer the selected data.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Can`t register Sql Connection

Post by HighAley »

Hello.

You should set Designer options before its' initialization.
Please, move next code to the OnPreInit event.

Code: Select all

StiOptions.Designer.HideConnectionString = true;
Thank you.
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Re: Can`t register Sql Connection

Post by Makarenya »

And nothing changed

Code: Select all

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connectionString = "Server=ZZZ";
            StiReport report = new StiReport();
            report.Dictionary.Databases.Add(new StiSqlDatabase("azure", connectionString));
            report.Dictionary.Restrictions.Add("azure", StiDataType.Database, StiRestrictionTypes.DenyShow);
            report.Dictionary.Restrictions.Add("azure", StiDataType.Database, StiRestrictionTypes.DenyEdit);
            StiWebDesigner1.Design(report);
        }

        protected void StiWebDesigner1_PreInit(object sender, StiWebDesigner.StiPreInitEventArgs e)
        {
            StiOptions.Designer.HideConnectionString = true;
        }
Connection string still visible, azure connection still editable
Makarenya
Posts: 6
Joined: Wed Aug 21, 2013 8:55 am

Re: Can`t register Sql Connection

Post by Makarenya »

I found a clean solution - use Stimulsoft Reports.Mobile Designer. RegData(connection) is work as mentioned. But he still raw - to succeed need sidebar, and in version 2013.1 is not. There are only betas. So do not see any reason to continue to torment unsafe approaches with flash and silverlight, and put another question: when will the full-fledged editor for html5? Need more or less the exact date - this is important!
Post Reply