FAQ/switching-databases-via-code.md
... ...
@@ -20,6 +20,21 @@ public static void InitializeReporting() {
20 20
21 21
This is a simple method that will connect the user to the database called "Administration" if that user is an admin. You can, however, also switch databases on the fly during runtime.
22 22
23
+##Using the Query String
24
+
25
+To dynamically change your connection string via a query string parameter, you can add code like this to the Report Designer, Report List, and Report Viewer. If a "db" parameter is found, it will change the connection string.
26
+
27
+```csharp
28
+protected override void OnInit(EventArgs e)
29
+{
30
+ string db = Request.QueryString["db"];
31
+ if (db != null)
32
+ Izenda.AdHoc.AdHocSettings.SqlServerConnectionString = "server=(local);Trusted_Connection=True;database=" + db;
33
+
34
+ base.OnInit(e);
35
+}
36
+```
37
+
23 38
##Custom Button
24 39
25 40
This sample page can be used to create a drop down & button to dynamically change the database connection string during runtime. Simply add this new page to the folder where your reporting website exists. When the database from the dropdown is selected and the button is clicked, the connection string associated to that database is selected. The application will now use the updated data source information.