Integration/Tutorials/connect-to-the-database.md
... ...
@@ -112,4 +112,41 @@ If you wish to test your connection string to ensure connectivity, you can perfo
112 112
* Click "Test" below the connection string
113 113
* Text will appear below the field describing either "SUCCESS" or "FAILURE". Failure lists the reason why it failed.
114 114
115
-![](/Integration/Tutorials/connect-to-the-database/settings_aspx.png)
... ...
\ No newline at end of file
0
+![](/Integration/Tutorials/connect-to-the-database/settings_aspx.png)
1
+
2
+##Per-user database connections
3
+
4
+If you wish to have different connections for different users, it can be accomplished easily in Izenda by simply setting up a conditional section in your InitializeReporting method to check whether your condition is true or not before setting the connection string. By default, this setting is initialized with each user who logs in or accesses the application. If you already have a login process in place with the conditions for each user's connection already worked out, then it is simply a matter of setting the connection string. Below is an example of a multi-conditional connection string. In the example, **WebServiceRequest** is a static interface to a web service that has a method called **GetCurrentApplicationUser** that returns an object of type **User**.
5
+
6
+**C♯ example**
7
+
8
+```csharp
9
+public static void InitializeReporting() {
10
+ //Check to see if we've already initialized.
11
+ if (HttpContext.Current.Session == null || HttpContext.Current.Session["ReportingInitialized"] != null)
12
+ return;
13
+ User myApplicationUser = WebServiceRequest.GetCurrentApplicationUser(); //your method for obtaining the authenticated user
14
+ AdHocSettings.CurrentUserName = myApplicationUser.UserName; //Set the CurrentUserName
15
+ if (myApplicationUser.IsAdministrator)
16
+ AdHocSettings.SqlConnectionString = WebServiceRequest.GetConnectionStringForAdmin(); //Set the connection string for an admin
17
+ else
18
+ AdHocSettings.SqlConnectionString = WebServiceRequest.GetConnectionStringForUser(); //Set the connection string for a regular user
19
+}
20
+```
21
+
22
+**VB.NET example**
23
+
24
+```visualbasic
25
+Public Shared Sub InitializeReporting()
26
+ 'Check to see if we've already initialized.
27
+ If HttpContext.Current.Session Is Nothing OrElse HttpContext.Current.Session("ReportingInitialized") IsNot Nothing Then
28
+ Return
29
+ Dim myApplicationUser As User = WebServiceRequest.GetCurrentApplicationUser() 'your method for obtaining the authenticated user
30
+ AdHocSettings.CurrentUserName = myApplicationUser.UserName 'Set the CurrentUserName
31
+ If myApplicationUser.IsAdministrator Then
32
+ AdHocSettings.SqlConnectionString = WebServiceRequest.GetConnectionStringForAdmin() 'Set the connection string for an admin
33
+ Else
34
+ AdHocSettings.SqlConnectionString = WebServiceRequest.GetConnectionStringForUser() 'Set the connection string for a regular user
35
+ End If
36
+End Sub
37
+```
... ...
\ No newline at end of file