Passing a connection string from client application to server

Passing a connection string from client application to server can be done through parameters.


1. In report designer open the parameters collection editor (press Document  tab >  Parameters)




2. Add a new parameter and set the 'Name' value as 'ConnectionString'. You can leave the other fields with default values.



3. Add the following code to Document's GenerateScript:

(Document.DataSources["DataSource1"] as PerpetuumSoft.Reporting.Data.SqlBaseDataSource).ConnectionString = GetParameter("ConnectionString").ToString();



4. Then,  set the value of parameter in WPF application before the call for document rendering occurs:

reportViewer.Parameters.Add("ConnectionString", "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True");
reportViewer.RenderDocument();

Add Feedback