Print Page | Close Window

Switching Connection String at Runtime

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1860
Printed Date: 21-Apr-2026 at 10:39am


Topic: Switching Connection String at Runtime
Posted By: jmarbutt
Subject: Switching Connection String at Runtime
Date Posted: 04-Jun-2010 at 11:08pm
Ok this is just a simple question, but how do I switch the connection string at run time based on the user login?



Replies:
Posted By: GregD
Date Posted: 07-Jun-2010 at 12:20pm
In the Learning Resources, see the material on DataSourceKeys, DataSourceKeyResolvers, and DataSourceExtensions in the Business Object Persistence_Advanced topic document. There are also two Visual Studio solutions that address the topic, both in the folder Learning Resources\040_BusObjPersistence\DataSourceKeys.


Posted By: jmarbutt
Date Posted: 08-Jun-2010 at 3:16pm
Does this show how to do it only from the server side of the Silverlight application?


Posted By: GregD
Date Posted: 08-Jun-2010 at 5:41pm
Tell me a bit more about what you're trying to do.


Posted By: jmarbutt
Date Posted: 08-Jun-2010 at 7:12pm
I am wanting to change the connection based on the authenticated user.

I am also trying to implement the custom authentication but haven't gotten that working yet either.


Posted By: DavidKozikowski
Date Posted: 09-Jun-2010 at 6:12am
Originally posted by GregD

In the Learning Resources, see the material on DataSourceKeys, DataSourceKeyResolvers, and DataSourceExtensions in the Business Object Persistence_Advanced topic document. There are also two Visual Studio solutions that address the topic, both in the folder Learning Resources\040_BusObjPersistence\DataSourceKeys.
 

The info in that section of documentation for DevForce 2010 states "Coming Soon!"

I do need some help / direction on what the App.Config file needs to look like when there are several databases involded. Can you provide a sample App.config file?
 


Posted By: GregD
Date Posted: 09-Jun-2010 at 5:45pm
Originally posted by jmarbutt

I am wanting to change the connection based on the authenticated user.


Sure, but I don't understand why you asked this question:

Originally posted by jmarbutt

Does this show how to do it only from the server side of the Silverlight application?


The only place the connection string will be used is server-side.


Posted By: GregD
Date Posted: 09-Jun-2010 at 5:47pm
Originally posted by DavidKozikowski

The info in that section of documentation for DevForce 2010 states "Coming Soon!"


Maybe we just got it back in there for this release. I was looking at the docs going out with 6.0.3.


Posted By: jmarbutt
Date Posted: 10-Jun-2010 at 10:23am
I think my question around this is how does the EntityManager know how to use the CustomDataSourceKeyResolver? I don't see it assigned any where.


Posted By: jmarbutt
Date Posted: 10-Jun-2010 at 10:30am
Nevermind, I guess it is using reflection to do that, pretty cool, but could be better documented about that.


Posted By: kimj
Date Posted: 10-Jun-2010 at 11:01am
You're right that we're still missing documentation on how DevForce probes for custom implementations.  Briefly, we're using MEF (Managed Extensibility Framework) for most probing.  When you implement a DevForce interface, or sub-type a base class, that type has been marked with the MEF InheritedExport attribute, which means that when a custom implementation is supplied MEF "should" find it.  By default, in a .NET application that discovery will be in the exe/bin folder, and in Silverlight the XAP file. 
 
As for what's used server-side vs. client side, or both, right now that's usually described in the API Reference Help.  There's also more information in the Deployment chapter in the Learning Resources.  In the case of the IDataSourceKeyResolver, although you can deploy your custom class to both client and server, it's only on the server that actual connection string resolution is required.


Posted By: jmarbutt
Date Posted: 10-Jun-2010 at 11:34am
Do you have any data in that sample app? It appears that I am not building my connection string correctly, I would like to compare what the connection string being past to the ClientEdmKey.

I think I just have something slightly off.


Posted By: GregD
Date Posted: 10-Jun-2010 at 4:01pm
See the Data folder that accompanies the two DataSourceKey solutions. It contains two zips which contain a total of three databases: Tenant, Tomato01, and Tomato02. You need to attach those to your instance of SQL Server.



Print Page | Close Window