Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Open the same database with different users
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Connections and Data Store Management > How to: Open the same database with different users

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

Telerik OpenAccess ORM supports only a single connection pool that has to be used by all users. In order to achieve that every user has to have a separate connection settings with a different connection id. Otherwise the same database object would be returned to different users. Below is a small code snippet showing how to open the same database with different users.

C# Copy Code
class DatabaseHelper  
{  
internal static IObjectScope GetNewObjectScope(string username, string password)  
{  
string myconfig =  
    
"<openaccess>" +  
    
"<references>" +  
    
// refer the DAL assembly with app.config with backendconfig section  
    
"<reference assemblyname='db2users' />" +  
    
"</references>" +  
    
"<connections>" +  
    
"<connection id=\"" + username + "Id\">" +  
    
"<databasename>Database1</databasename>" +  
    
"<servername>localhost</servername>" +  
   
"<integratedSecurity>false</integratedSecurity>" +  
   
// insert the right backendconfigurationname here  
   
"<backendconfigurationname>mssqlConfiguration</backendconfigurationname>" +  
   
"</connection>" +  
   
"</connections>" +  
   
"</openaccess>";  
   XmlDocument xmlDoc =
new XmlDocument();  
   xmlDoc.LoadXml(myconfig);  
   
return Database.Get(username + "Id", xmlDoc.DocumentElement).GetObjectScope(username,password);  
   }  
}  

class Program  
{  
 
static void Main(string[] args)  
 {  
   IObjectScope scopeUser1 = DatabaseHelper.GetNewObjectScope(
"openaccess", "openaccess");  
   IObjectScope scopeUser2 = DatabaseHelper.GetNewObjectScope(
"telerik", "telerik");  
 }  
}   

 

VB.NET Copy Code
Class DatabaseHelper
    Friend Shared Function GetNewObjectScope(ByVal username As String, ByVal password As String) As IObjectScope
            ' refer the DAL assembly with app.config with backendconfig section
            ' insert the right backendconfigurationname here
        Dim myconfig As String = "<openaccess>" + "<references>" + "<reference assemblyname='db2users' />" + "</references>" + "<connections>" + "<connection id=""" + username + "Id"">" + "<databasename>Database1</databasename>" + "<servername>localhost</servername>" + "<integratedSecurity>false</integratedSecurity>" + "<backendconfigurationname>mssqlConfiguration</backendconfigurationname>" + "</connection>" + "</connections>" + "</openaccess>"
        Dim xmlDoc As New XmlDocument()
        xmlDoc.LoadXml(myconfig)
        Return Database.[Get](username + "Id", xmlDoc.DocumentElement).GetObjectScope(username, password)
    End Function
End Class

Class Program
    Shared Sub Main(ByVal args As String())
        Dim scopeUser1 As IObjectScope = DatabaseHelper.GetNewObjectScope("openaccess", "openaccess")
        Dim scopeUser2 As IObjectScope = DatabaseHelper.GetNewObjectScope("telerik", "telerik")
    End Sub
End Class