Multiple DB with the same name

7 posts, 1 answers
  1. Jassey Nguyen
    Jassey Nguyen avatar
    6 posts
    Member since:
    May 2008

    Posted 08 Dec 2009 Link to this post

    I am using the AdjustForDynamicLoad Method and I modified it to pass in my connection settings.

    static public void AdjustForDynamicLoad(string server, string dbname, string username, string password,bool integratedSecurity) 
            { 
                //if (theObjectScopeProvider1 == null) 
                    theObjectScopeProvider1 = new ScopeProvider(); 
                if (theObjectScopeProvider1.myDatabase == null
                { 
                    string assumedInitialConfiguration = 
                         "<openaccess>" + 
                          "<references>" + 
                           "<reference assemblyname='PLACEHOLDER' configrequired='True'/>" + 
                          "</references>" + 
                          "<connections>" + 
                         @"<connection id=""{0}"">" + 
                          "<databasename>{0}</databasename>" + 
                            @"<servername>{1}</servername>" + 
                          "<integratedSecurity>{4}</integratedSecurity>" + 
                          "{2}" + 
                          "{3}" +  
                          "<backendconfigurationname>mssqlConfiguration</backendconfigurationname>" + 
                         "</connection>" + 
                        "</connections>" + 
                         "</openaccess>"
                    string config = ""
                    if (integratedSecurity) 
                    { 
                        config = string.Format(assumedInitialConfiguration, dbname,server, """", integratedSecurity.ToString());                         
                    } 
                    else 
                    { 
                        config = string.Format(assumedInitialConfiguration, dbname,server, string.Format("<user>{0}</user>", username), string.Format("<password>{0}</password>", password), integratedSecurity.ToString()); 
                    } 
                    System.Reflection.Assembly dll = theObjectScopeProvider1.GetType().Assembly; 
                    assumedInitialConfiguration = config.Replace( 
                             "PLACEHOLDER", dll.GetName().Name); 
                    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); 
                    xmlDoc.LoadXml(assumedInitialConfiguration); 
                    Database db = Telerik.OpenAccess.Database.Get(dbname, 
                           xmlDoc.DocumentElement, new System.Reflection.Assembly[] { dll }); 
                     
                    theObjectScopeProvider1.myDatabase = db; 
                } 
            } 

    The problem is we use this to point to the same database on several different servers.  Is there a better way of changing the connection since if you use the same connection id Telerik.OpenAccess.Database.Get returns the initial database.  I don't want to call it a bug but this doesn't seem like appropriate behavior.  If I call Get and pass in a new xmlDoc then it should do the get on that xmldoc and not what's in memory.

  2. Answer
    TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 09 Dec 2009 Link to this post

    Hi Jassey,

    I think this is behavior by design, without knowing it for sure.

    Alexander from the Telerik Team showed me another implementation instead of using the way of passing in XML. You can see his solution here. Maybe you can try it out, I haven't got the time do so yet.

    However, it seems like the Database.Get(....) call is caching the connection information for the respective connection ids. Maybe a solution would be to provide different connection ids in the Database.Get(...) calls.

    Hope I did point you in the right direction.

    Regards

    Henrik

  3. DevCraft banner
  4. Jassey Nguyen
    Jassey Nguyen avatar
    6 posts
    Member since:
    May 2008

    Posted 09 Dec 2009 Link to this post

    Hi Henrik,

    I still think that the fact that it caches the connection string even if I pass in a new xml doc is a bit misleading.  If all that I supply is the connectionId then yes this would be expected, but if I'm passing in the xmldoc why would I want them to pull the same information from a previously cached version.

    Also I can't find a reference to the BackendConfiguration class anywhere...what do I need to use that.

    Thanks for your help.
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 09 Dec 2009 Link to this post

    Hi Jassey,

    I share your statement, that this is a bit misleading, like: "Hey, I pass you this connection info, use it no matter what you did before".

    Regarding the BackendConfiguration: Are you using the Q3 build? I think this API is only available from that release.

    Anyway, did you try to use different connection ids for your two connection strings? I think this should do the trick.

    Regards

    Henrik
  6. Jassey Nguyen
    Jassey Nguyen avatar
    6 posts
    Member since:
    May 2008

    Posted 09 Dec 2009 Link to this post

    Hi Henrik,

    >Regarding the BackendConfiguration: Are you using the Q3 build? I think this API is only available from that release.

    Yes I'm using the Q3 version of OA.  I did a "ctrl ." and it didn't suggest a using so I'm not sure what I'm missing.

    >Anyway, did you try to use different connection ids for your two connection strings? I think this should do the trick.

    Yes this did do the trick.  

    I'm curious though I haven't been able to try it because of the missing class, but if I pass in the ConnectionString class does it still have the ConnectionId limitation or does that somehow bypass it?

    Thanks

  7. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 10 Dec 2009 Link to this post

    Hi Jassey,

    The BackendConfiguration class is located in the Telerik.OpenAccess.Config namespace.

    Apply this namespace to your using section and try it out.

    /Henrik
  8. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 10 Dec 2009 Link to this post

    Hello Jassey,

     Yes, if you use the BackendConfiguration approach even if the connection id is already used in the config file for another connection, it will be overridden.


    Sincerely yours,
    Jordan
    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.
Back to Top
DevCraft banner