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

How do I override openaccess connection string during runtime?

3 Answers 154 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James
Top achievements
Rank 1
James asked on 11 May 2011, 09:46 AM
G'Day,

We are rolling out an upgraded version of our CMS using Telerik OpenAccess.

In part of this package is a setup routine, which accepts a new database connection string. Setup connects to the new database, creates all the database objects (using scripting) then connects using OpenAccess to populate the tables.

We are changing the Telerik connection string programmatically. Problem is, Telerik appears to be caching the old connection string (ie. the one in web.config at the time website is loaded). Web.Config snippit below:

<connectionStrings>
  <add name="MainConnection" connectionString="Packet Size=4096;Data Source='(local)'; Initial Catalog='EITCMS_TEST6';User Id='eitcms';Password='eitcms';Persist Security Info=False;" />
</connectionStrings>
<openaccess xmlns="http://www.telerik.com/OpenAccess">
  <references>
    <reference assemblyname="EITCMS.DataAccess" configrequired="True" />
  </references>
</openaccess>

Could you please advise how to override the database that Telerik is using. I have attempted to look at connectionpools of the backend configuration for the scope provider but there appears to be no way to override the connection.

Note that this line fails to use the new connection string:

theEITCMSObjectScopeProvider._myDatabase = Telerik.OpenAccess.Database.Get("MainConnection")

Appears to be caching the original connection string.

What am I doing wrong? Has anybody attempted to do this?

Thank You,
James

3 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 14 May 2011, 09:43 PM
Hi James,

 What actually happens is that once a Database.Get call  is executedwith a certain connection string name it is cached. This means that for each connection string name there is a single database object. This is done because the retrieval (initialization) of a database object is actually a operation that is not that cheap. Whenever a Database.Get is executed the model that is retrieved from your mapping is further calculated based on your backend and this is timeconsuming.

However if you want to make sure that it is recreated and not cached you can just retrieve it, dispose of it and then try to retrieve it again, this will make sure that the new connection string will be used. 

If that is not your case please do let us know so that we can further investigate and resolve this issue. 

I am looking forward to hearing from you again.

Best wishes,
Serge
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
James
Top achievements
Rank 1
answered on 18 May 2011, 01:33 AM
Thanks for your reply. Sorry for taking so long to get back to you...

I tried this code in the objectscopeprovider:

Public Shared Function Database() As Database
    theEITCMSObjectScopeProvider = Nothing
    If theEITCMSObjectScopeProvider Is Nothing Then
        theEITCMSObjectScopeProvider = New EITCMSObjectScopeProvider()
    End If
    theEITCMSObjectScopeProvider._myDatabase = Nothing
    If theEITCMSObjectScopeProvider._myDatabase Is Nothing Then
        theEITCMSObjectScopeProvider._myDatabase = Telerik.OpenAccess.Database.Get("MainConnection")
    End If
    Return theEITCMSObjectScopeProvider._myDatabase
End Function

However, the connection string being used from web.config is still the old one.

What am I doing wrong? Looking forward to your reply...

Thanks,
James
0
Alexander
Telerik team
answered on 20 May 2011, 01:02 PM
Hi James,

Actually you need to force the database object to be disposed by calling its Dispose method. Please try this code:
theEITCMSObjectScopeProvider._myDatabase.Dispose()
instead of:
theEITCMSObjectScopeProvider._myDatabase = Nothing

Hope that helps.

Greetings,
Alexander
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
Databases and Data Types
Asked by
James
Top achievements
Rank 1
Answers by
Serge
Telerik team
James
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or