This is a migrated thread and some comments may be shown as answers.

Database connection strings from a database

3 Answers 105 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alessandro Federici
Top achievements
Rank 1
Alessandro Federici asked on 30 Nov 2009, 05:49 PM
Hi,
  I just started the evaluation of OA and I like what I see so far very much. I have one big problem and I couldn't find any post or article that clearly helped me resolving this issue. I am writing a system that connects to many databases (75+). These databases have different schemas (20 have schema A, 10 schema B, etc) and for each I will generate a DAL library using OA. So, all good so far. The problem is that the connection information for those databases is... in a database (the main dbof our product) which lists things like this:

---Datasources---
Id (string)
Name (string)
ConnectionString (string)
DALLibrary (string)

What I need is, essentially, change the connection string of a OA library and make it point to the instance I am interested in.
Storing this kind of information in Config files is absoutely NOT an option (for obvious security reasons and other design reasons) but all I saw, so far, seems to point to the fact OA needs that info in config files. I've seen the overloads that allow you to pass an XElement but I found no examples of how to use that (and that seems the workaround to my problem).

Can anybody help?

Thanks a lot!

Alessandro Federici










3 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 01 Dec 2009, 08:59 AM
Hi Alessandro,

One way I could think of was to extend the object scope provider (gets generated for you by OA Wizard when you enabled a project) to support multiple Database objects (that is the Telerik defined Database class).

Because if you look at this in the documentation it can take an XML configuration like the one below:

<connections> 
     <connection id="ArchiveConnection"
       <databasename>ArchiveDB</databasename> 
       <servername>(local)\SQLEXPRESS</servername> 
       <integratedSecurity>True</integratedSecurity>                     
     <backendconfigurationname>ArchiveConfiguration</backendconfigurationname> 
     </connection> 
</connections> 


Now, the trick is to transform the information in your database to something like the above, eventually including also the references section at runtime...

Like a method (still based on the original ObjectScopeProvider.cs) called.... GetNewObjectScope(string datasourceId), where datasource Id is the one you have in your table.

Within the GetNewObjectScope(string) method, you query your database for the connection string, dynamically create a xml snippet and pass it to the Database.Get(...) method as parameter.... Once you have the Database instance you can store it within a Dictionary<string, Database> type for further references.. and then you use the instance to do a databaseInstance.GetObjectScope() like normally in the ObjectScopeProvider.

Hope you get the idea. The link to the doc also has an example config, which should get you started.

Regards

Henrik

0
Alessandro Federici
Top achievements
Rank 1
answered on 01 Dec 2009, 01:33 PM
Thank you. I'll look into it
0
Alexander
Telerik team
answered on 01 Dec 2009, 02:16 PM
Hello Alessandro Federici,

I would like to add that you should be able to use the new connection settings that work with standard .NET connection strings (introduced in the 2009 Q3 version). With a connection string the connection node would look like this:
...
<connections>
   <connection id="DatabaseConnection1">
      <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
      <connectionString>Data Source=(local)\sqlexpress;Initial Catalog=Northwind;Integrated Security=True</connectionString>
   </connection>
</connections>
...
The rest of the configuration is the same.

All the best,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Getting Started
Asked by
Alessandro Federici
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Alessandro Federici
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or