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

Reverse Mapping Process

6 Answers 285 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ray
Top achievements
Rank 1
Ray asked on 15 Oct 2009, 01:43 AM
I know that I am missing a step in as I attempt to use openAccess to setup a very simple database wit a few fields. I have been working on establishing the right process which has eluded me dispite the different documents which I found are slightly different (process). Here is the process that I have been using and hopefully someone will be able to correct me of my ways.

 

1.      Create a Class Library Class solution

a.       Solution Name: ORM1

b.      Class Project: ORMClass

2.      I enable OpenAccess

3.      Select Persistent classes

4.      Assign

a.       Connection ID = mydb

b.      Server Name = innovator

c.       Database Name = dbORM

5.      Click on Test button and get dialog box with a good connection message.

6.      Click Finish.

7.      Select OpenAccess and select reverse mapping

8.      Click on Generate & Save Configuration (two simple tables)

9.      Create a new project by selecting New -> New Project and select Web Application

10.  Enable project to ORM (Select OpenAccess > Enable Project to Use ORM)

11.  Add reference to class project (ORMClass)

12.  Open default.aspx

13.  Add Telerik RADscriptmanager and radgrid.

14.  Set configuration for radgrid to use ORM connection.

15.  Compile

16.  Run

17.  Get following error:

 

The connection section with id 'mydb' cannot be found in the configuration files traversed from '(OpenAccess internally generated, maybe web page)'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Telerik.OpenAccess.Exceptions.ConfigurationException: The connection section with id 'mydb' cannot be found in the configuration files traversed from '(OpenAccess internally generated, maybe web page)'.


Source Error:

 

Line 59:

Line 60:                  If theObjectScopeProvider1._myDatabase Is Nothing Then

Line 61:             theObjectScopeProvider1._myDatabase = Telerik.OpenAccess.Database.Get("mydb")

Line 62:         End If

Line 63:


Source File: C:\MyVS2008\orm1\ormweb1\ObjectScopeProvider1.vb    Line: 61

Stack Trace:

 

[ConfigurationException: The connection section with id 'mydb' cannot be found in the configuration files traversed from '(OpenAccess internally generated, maybe web page)'.

]

   Telerik.OpenAccess.Config.Connection.ConnectionParser.GetConnectionData(String connectionId, String apiUser, String apiPassword, ArrayList mappingXmlNodes, ArrayList mappingSources, XmlElement openAccessNode, ReferenceData[] refs, String configFileName, Boolean partial) +473

   Telerik.OpenAccess.Config.Connection.ConnectionManager.GetConnectionData(String connectionId, String apiUser, String apiPassword, ArrayList mappingXmlNodes, ArrayList mappingSources, XmlElement openAccessNode, ReferenceData[] refs, String configFileName, Boolean partial) +60

   Telerik.OpenAccess.Config.ConfigManager.GetConnectionData(String apiUser, String apiPassword, ArrayList mappingXmlNodes, ArrayList mappingSources, Boolean partial) +126

   Telerik.OpenAccess.Config.ConfigManager.GetConnectionData(String apiUser, String apiPassword, Boolean partial) +115

   Telerik.OpenAccess.Config.ConfigManager.GetConnectionData(String apiUser, String apiPassword) +42

   Telerik.OpenAccess.Config.ConfigManager.MapConnectionId2Url() +40

   Telerik.OpenAccess.DBRegistry.GetDatabase(String urlOrConnectionId, XmlElement configOverride, Assembly[] entryAssemblies) +316

   Telerik.OpenAccess.DBRegistry.GetDatabase(String urlOrConnectionId, XmlElement configOverride) +90

   Telerik.OpenAccess.Database.Get(String connectionId) +149

   ormweb1.ObjectScopeProvider1.Database() in C:\MyVS2008\orm1\ormweb1\ObjectScopeProvider1.vb:61

   ormweb1.ObjectScopeProvider1.GetNewObjectScope() in C:\MyVS2008\orm1\ormweb1\ObjectScopeProvider1.vb:78

 

[TargetInvocationException: Exception has been thrown by the target of an invocation.]

   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0

   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71

   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +350

   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29

   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19

   Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ConstructContext() +892

 

[InvalidOperationException: No constructor for the strongly-typed IObjectScope takes 0 parameters.]

   Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ConstructContext() +1014

   Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +126

   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19

   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142

   Telerik.Web.UI.GridTableView.PerformSelect() +28

   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73

   Telerik.Web.UI.GridTableView.DataBind() +365

   Telerik.Web.UI.RadGrid.DataBind() +165

   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82

   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72

   System.Web.UI.Control.EnsureChildControls() +87

   System.Web.UI.Control.PreRenderRecursiveInternal() +44

   System.Web.UI.Control.PreRenderRecursiveInternal() +171

   System.Web.UI.Control.PreRenderRecursiveInternal() +171

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

 

 
Any help will be greatly appreciated.

Ray

6 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 15 Oct 2009, 05:45 PM
Hello Ray,

You could use the two advises I would like to give you regarding the situation you are having:

1.    First thing I would like to share is that you have done a fairly good job if we take into account that you are probably new to OpenAccess. This means that you have taken the right approach into building a web site with OpenAccess. The steps you have described are the ones you should generally follow.

 The one little difference you should account for is swapping the order of steps: 10 and 11. The reason for this is that if you enable your web project and then add a reference to the persistent classes project(as you have done in your first try), OpenAccess does not know of the reference while enabling the project. This fact is quite critical because in this case we do not generate the required <reference> node that 'tells' OpenAccess where should it eventually search for persistent classes and connections. Doing it the other way around, will add the reference node in the web.config automatically.


2.  If you are not keen on going through the same steps once again, and would like to continue on the development of your project, here are the steps you should execute to manually solve your problem:

-    Open the web.config file in the web application project;
-    Locate the references node;
-    Alter the references node so that it gets the following form:

<references>
     <reference assemblyname="ORMClass" configrequired="True" />
</references>

This should be enough for you to get started with OpenAccess. As soon as any additional questions arise, we are looking forward for your future feedback.


Kind regards,
Damyan Bogoev
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.
0
Ray
Top achievements
Rank 1
answered on 15 Oct 2009, 07:20 PM
Damyan,

Yes, you are correct in that I am now taking a deep dive into OpenAccess. So far, the potential of this tool is considerable. Thank you for the complements as well.

I will run through another setup later tonight using your advice which I am certain will work fine. Thank you very much for your response as it is very much appreciated.

Ray
0
Ray
Top achievements
Rank 1
answered on 16 Oct 2009, 03:12 AM

I received the same error however I was able to fix the error as I descibe below.

I created another ORM enabled web application using the same steps as I previously identified however switching steps 10 and 11. This time around, the correct reference line was added to the web.config.

 

When I ran the web application, I received the same error. As I checked into the error closer, the error was in ObjectScopeProvider (my ProductScopeProvider.vb). In Sub AdjustForDynamicLoad() and Function Database, the code lines are causing the problem.

 

'DatabaseConnection1

theObjectScopeProvider1._myDatabase=Telerik.OpenAccess.Database.Get(

"DatabaseConnection1", xmlDoc.DocumentElement, allDlls)

 

If theObjectScopeProvider1._myDatabase Is Nothing Then

theObjectScopeProvider1._myDatabase=Telerik.OpenAccess.Database.Get(

"DatabaseConnection1")

End If

 

When I changed “DatabaseConnection1” to the actual Connection ID (myNorthwindConnection), the application displayed the data from the Northwind Product table.

 

Question: Is this a named reference that should be changed by the ORM during the configuration process or is this a manual configuration step that I need to remember? If it should be configured by the ORM, what did I miss?

Thanks!
Ray

0
Accepted
Damyan Bogoev
Telerik team
answered on 16 Oct 2009, 04:28 PM
Hello Ray,

In this case the data access code (ProductScopeProvider) is created inside the web application project. When you try to get new object scope object via the ProductScopeProvider.GetNewObjectScope() method you use “Database Connection1” which is the default connection id. That’s why the ProductScopeProvider should be altered manually as you did. If you do not want to use this approach you should do the following steps:
1.    When you enable the ORMClass project to use Telerik OpenAccess ORM you should enable Data access code(DAL)  setting too;
2.    Disable the preceding setting when you enable the web application project;

In your web application, use the ProductScopeProvider from the referenced ORMClass project.
I hope that the information finally solves your issue.

Kind regards,
Damyan Bogoev
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.
0
Erik
Top achievements
Rank 2
answered on 01 Aug 2010, 12:07 PM
Hello all,

Well... I got this error a lot: (using latest version in trial)
The connection section with id '...EntityDiagrams' cannot be found in the configuration files traversed from '(OpenAccess internally generated, maybe web page)'. 
Always in ObjectScopeProvider1 Function Database.

Spent some time now... Weird thing is that first i got the error only when trying to connect via ScopeProvider (not with context provider) in the global.asax.vb on session start, but if I tried later in a test default.aspx.vb load event, no problem. transactions worked fine, tracking worked fine. But, than later on, i got this error always. So I started a new project, same problem then. Created a separate project with persistant classes and a rlinq, also same error.

It seems that at the time of connecting, the Database.Get cannot access the app.config or web.config and does therefore not know the connection string. So, I struggled on, and came up with this:

Public Shared Function Database() As Database
    If theObjectScopeProvider1 Is Nothing Then
        theObjectScopeProvider1 = New ObjectScopeProvider1()
    End If
 
    If theObjectScopeProvider1._myDatabase Is Nothing Then
        Dim backend As BackendConfiguration = GetBackendConfiguration()
        Dim MDS As MetadataSource = XmlMetadataSource.FromAssemblyResource("EntityDiagrams.rlinq")
        Dim MDC As MetadataContainer = MDS.GetModel()
        theObjectScopeProvider1._myDatabase = Telerik.OpenAccess.Database.Get("<<app/web.config connection id>>", backend, MDC)
    End If
 
    Return theObjectScopeProvider1._myDatabase
End Function
 
' Copied form autogenerated OpenAccessContext file
Private Shared Function GetBackendConfiguration() As BackendConfiguration
    Dim backend As BackendConfiguration = New BackendConfiguration()
    backend.Backend = "mssql"
    Return backend
End Function


This seems to be working, but I don't know if this is the right approach?
What say you? 

Erik
0
Damyan Bogoev
Telerik team
answered on 03 Aug 2010, 06:49 PM
Hi Proovit,
It is not recommended to use a Domain Model with an ObjectScopeProvider. It is actually not necessary either. You could just instantiate an OpenAccessContext object like this:

Dim context As New YourContextName()

I would recommend you to read this help article section which explains how to query data using a domain model.
In case you want to use an IObjectScope instance instead of an OpenAccessContext you can extend your OpenAccessContext class where you have to expose the IObjectScope object as shown below. Normally you would not have to do this.

Public Partial Class YourContextName
Public ReadOnly Property Scope() As IObjectScope
Get
Return Me.GetScope()
End Get
End Property
End Class

Hope that helps.

Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Getting Started
Asked by
Ray
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Ray
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Share this question
or