Dofactory.com
Dofactory.com
 Back to list
Views:   5.4K
Replies:  1
Archived

Changing connection string

Using Spark framework with .NET MVC 4, we have a need to change database connection based on user profile located in central database.

e.g we have 10 application database instance with similar schema definition and a user in one instance may or may not have permission to see data in other db.

It is one solution application and can not have multiple domain layers , also we can not merge all instance data and create one back-end solution. Given that server connection remains same only initial catalog name changes what would be the best way to achieve this per controller/request context  (may be using dependency injection) ? 

Thanks!
Lauren Kruglak, Oct 17, 2014
Reply 1
Hello Lauren:

This is an unusual situation. 

My initial response would be to merge those databases and add a db identifier to each record.
(I realize that this is not an option)..

My next response would be to create 10 separate domain projects, although the data model is the same for each database.
(I realize that this is not an option - although you can always move the domain code to the main project and remove the domain projects) 

The 10 domain projects will create the same objects in different namespaces for each table.
All this is strange and is unnecessary code duplication because the databases are the same.

When using only 1 domain project, I was thinking that all the Repository methods perhaps can be customized to accept a connection string (name) for each request.. This may be possible, but requires a good understanding of the underlying Core.cs and Repository.cs files (the good news is that you have all the source code). 

There is no doubt that something can be done, but at this point I am not certain what the most optimal solution is. 
It all requires some experimentation.  Hope this gets you going. 
Jack Poorte, Oct 20, 2014
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.