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

Multiple DB with the same name

6 Answers 82 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jassey Nguyen
Top achievements
Rank 2
Jassey Nguyen asked on 08 Dec 2009, 09:29 PM
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.

6 Answers, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 09 Dec 2009, 07:49 AM
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

0
Jassey Nguyen
Top achievements
Rank 2
answered on 09 Dec 2009, 02:24 PM
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.
0
IT-Als
Top achievements
Rank 1
answered on 09 Dec 2009, 02:31 PM
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
0
Jassey Nguyen
Top achievements
Rank 2
answered on 09 Dec 2009, 06:17 PM
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

0
IT-Als
Top achievements
Rank 1
answered on 10 Dec 2009, 08:27 AM
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
0
Jordan
Telerik team
answered on 10 Dec 2009, 08:57 AM
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.
Tags
Development (API, general questions)
Asked by
Jassey Nguyen
Top achievements
Rank 2
Answers by
IT-Als
Top achievements
Rank 1
Jassey Nguyen
Top achievements
Rank 2
Jordan
Telerik team
Share this question
or