Print Page | Close Window

is there a way to get the connection string

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1355
Printed Date: 22-Sep-2025 at 4:22am


Topic: is there a way to get the connection string
Posted By: monkeyking
Subject: is there a way to get the connection string
Date Posted: 29-Jun-2009 at 11:57pm
I want to get the connection string



Replies:
Posted By: monkeyking
Date Posted: 30-Jun-2009 at 12:31am
            int count = 0;
            var query = AdditionalFunctions.manager.DataSourceResolver.DataSourceKeyNames;
           
            foreach (string s in query)
            {
                count++;
            }
            MessageBox.Show(count.ToString());

I wrote these code, but the message box says '0'. I'm not sure if i'm doing correct way.


Posted By: kimj
Date Posted: 30-Jun-2009 at 10:39am
The DataSourceResolver, although a public type, is primarily intended for internal use.  The DataSourceKeyNames (and DataSourceKeys, along with several other properties) are only loaded after several other trigger events. 
 
The best thing to use to look at connection strings in the IdeaBladeConfig.EdmKeys collection, like this:
 
      foreach (var key in IdeaBladeConfig.Instance.EdmKeys) {
        Debug.WriteLine(key.Name + ": " + key.Connection);
      }
If you omit the connection information from your client-side EdmKeys in an n-tier configuration (as you should), then the connection information is available only from server-side code.


Posted By: monkeyking
Date Posted: 30-Jun-2009 at 5:03pm
thanks kimj, you are very helpful. 


Posted By: monkeyking
Date Posted: 30-Jun-2009 at 5:54pm
hi kimj, sorry, i don't have an Edmkeys property in my IdeaBladeConfig.Instance, should I do sth first to make it appear?


Posted By: kimj
Date Posted: 30-Jun-2009 at 7:12pm
EdmKeys is a public property on the IdeaBladeConfig class.  IdeaBladeConfig.Instance is the singleton instance of your loaded configuration information (from app.config or web.config).  This class is defined in IdeaBlade.Core, so you need an assembly reference to that, and a Using statement for the namespace. 


Posted By: monkeyking
Date Posted: 01-Jul-2009 at 12:13am
thanks kimj, you are very helpful. 


Posted By: monkeyking
Date Posted: 01-Jul-2009 at 12:22am
one more question, can I detect which key is currently being used? i might have many keys, but only one DB has been connected, is there a way to detect that?


Posted By: kimj
Date Posted: 01-Jul-2009 at 8:10am
Back to the DataSourceResolver.  The GetDataSourceKey() function will load the key information if necessary.
 
   _entityManager.DataSourceResolver.GetDataSourceKey(typeof(Customer));



Print Page | Close Window