We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Json web datasource at runtime example

is there an example of changing the datasource of a dashboard file at runtime?  In particular using a web data source with parameters in an asp.net mvc application.

Many thanks.


1 Reply

RN Renuka N Syncfusion Team April 2, 2019 09:40 AM UTC

Hi David  
Thanks for contacting Syncfusion Support.  
 You can change the Connection string of a dashboard using onApplyConnection Event API. Please refer the following link  to pass the connection string in the event 
Note : Refer the Newtonsoft.Json assembly in addition to other assembly (Syncfusion.Dashboard.Encryption.dll) in your application. You can download NewtonSoft.json from here 
Since you are using the web data source, we have the below changes in the mentioned UG  
  1. Please use the modified below code snippet in controller of your application to generate the connection string for the dashboard created using web data source, instead of the below mentioned in UG.
 Modified Code Snippet: 
     ConnectionStringBuilder obj = new ConnectionStringBuilder(); 
     DashboardCryptoProvider provider = new DashboardCryptoProvider(EncryptionType.AES); 
     ConnectionParameters connectionParameter = new ConnectionParameters 
      Url : "", // Pass the web datasource url 
      UserName: "",  
      Password: "", 
      ConnectionProviderType connectionType = ConnectionProviderType.WebDataConnector; // Connection type used in the dashboard 
      OdbcDbmsType odbcType = OdbcDbmsType.None; // ODBC DBMS type, if any 
      Connection connectionName = new Connection { DataSources = new List<DataSourceConnectionString>() }; 
      connectionName.DataSources.Add(new DataSourceConnectionString 
      Name = "Northwind Traders Sales Analysis"// Nane of the Data Source while designing the Dashboard in the Dashboard Designer 
       ConnectionString = obj.GenerateConnectionString(connectionParameter, connectionType, odbcType) 
    ViewBag.EncryptedString = provider.DoEncryption(Converter.SerializeObject(connectionName)); // You can pass the encrypted String in the onApplyConnection event API to change the change connection String  
We will update the UG with the mentioned changes for changing connection string of the dashboard designed using web data source at the run time in our upcoming release. 
Please let us know, if you have any queries. 
Renuka N.

Live Chat Icon For mobile
Up arrow icon