The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Troubleshooting connection issues

Last post 04-07-2008, 3:02 PM by RobHudson. 2 replies.
Sort Posts: Previous Next
  •  04-07-2008, 1:25 PM 8759

    Troubleshooting connection issues

    I am attempting to implement a configless setup, but have not been successful.  I have read through all relevant forum posts, and have quadruple-checked my code to see if I can find the issue, but to no avail.

     I am running

    • EntitySpaces 2007.1.1210.0
    • MyGeneration 1.3.0.3
    • VS 2008
    • IIS7
    • ASP.Net 2.0
    • SQL Server 2005.

    Relevant code from Global.asax:

    Code:
    1        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    2            
    3            ' // --- create connection
    4            Dim conn As EntitySpaces.Interfaces.esConnectionElement = New EntitySpaces.Interfaces.esConnectionElement
    5            conn.Name = "esDefault"
    6            
    7            ' // --- This connection string would normally be populated at runtime... 
    8            ' // --- hardcoded for testing
    9            conn.ConnectionString = "Data Source=mdsandiego; Initial Catalog=CMS; User ID=xxxx; Password=xxxx"
    10           
    11           conn.Provider = "EntitySpaces.SQLClientProvider"
    12           conn.ProviderClass = "DataProvider"
    13           conn.SqlAccessType = EntitySpaces.Interfaces.esSqlAccessType.DynamicSQL
    14           conn.ProviderMetadataKey = "esDefault"
    15           conn.DatabaseVersion = "2005"
    16           
    17           ' // --- Assign the Default Connection --- 
    18           EntitySpaces.Interfaces.esConfigSettings.ConnectionInfo.Connections.Add(conn)
    19           EntitySpaces.Interfaces.esConfigSettings.ConnectionInfo.Default = "esDefault"
    20           
    21           ' // --- Assign the Factory --- 
    22           esProviderFactory.Factory = New EntitySpaces.LoaderMT.esDataProviderFactory()
    23       End Sub
    
    Code from Test.aspx.vb
    Code:
    1        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2            Dim oEdition As New BusinessObjects.ScEditions
    3    
    4            ' // This block of code grabs the connection string from es and performs the 
    5            ' // database lookup without using es.  This code succeeds.
    6            Dim cn As New SqlConnection(oEdition.es.Connection.ConnectionString)
    7            cn.Open()
    8            Dim cmd As New SqlCommand("select * from scEditions where EditionID=1", cn)
    9            Dim dr As SqlDataReader = cmd.ExecuteReader
    10           While dr.Read
    11               Response.Write(dr("EditionName") & "<HR>")
    12           End While
    13           dr.Close()
    14           cn.Close()
    15           dr = Nothing
    16           cmd = Nothing
    17           cn = Nothing
    18   
    19           ' // error occurs here
    20           oEdition.LoadByPrimaryKey(1)
    21           Response.Write(oEdition.EditionName & "<HR>")
    22   
    23           ' // if you comment out the above and do the thing without using primary key,
    24           ' // you still get the same result
    25           oEdition.Query.Where(oEdition.Query.EditionID = 1)
    26           oEdition.Query.Load()
    27           Response.Write(oEdition.EditionName & "<HR>")
    28       End Sub
    
    The error: 
     

    Object reference not set to an instance of an object.

    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: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 138:            query.Where(query.EditionID.Equal(editionID))
    Line 139:
    Line 140:			return query.Load()
    Line 141:			
    Line 142:		End Function

    Source File: D:\Webfolders\mydistrict.net_Admin\App_Code\EntitySpaces\Generated\ScEditions.vb    Line: 140

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       EntitySpaces.Interfaces.esDataProvider.esLoadDataTable(esDataRequest request, esProviderSignature sig) +36
       EntitySpaces.Interfaces.esDynamicQuery.Load() +511
       BusinessObjects.esScEditions.LoadByPrimaryKeyDynamic(Int32 editionID) in D:\Webfolders\mydistrict.net_Admin\App_Code\EntitySpaces\Generated\ScEditions.vb:140
       BusinessObjects.esScEditions.LoadByPrimaryKey(Int32 editionID) in D:\Webfolders\mydistrict.net_Admin\App_Code\EntitySpaces\Generated\ScEditions.vb:109
       EntitySpaces_test.Page_Load(Object sender, EventArgs e) in D:\Webfolders\mydistrict.net_Admin\entityspaces\test.aspx.vb:15
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Adapters.ControlAdapter.OnLoad(EventArgs e) +12
       System.Web.UI.Control.LoadRecursive() +2117945
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
    
     
     
    Other applications using the same connection string (including MyGeneration and the main web application) function flawlessly.
     
    Is there any way to get additional error information about what caused the statement to fail?  Ideally, I'd like to see the exact error message received by the es object when it attempts to gain the connection and load the data.  Is it possible to grab the SQL statement just before it's being executed to see if there's a problem there?
     
    Do you see any other obvious errors in my implementation?
     
    Thanks,
     
    Rob Hudson
    MyDistrict.Net

    There are 10 kinds of people in the world... Those who understand binary, and those who don't.
  •  04-07-2008, 1:40 PM 8760 in reply to 8759

    Re: Troubleshooting connection issues

    The only thing I see wrong in your connection setting routine is "EntitySpaces.SQLClientProvider" instead of "EntitySpaces.SqlClientProvider" I think it may be case sensitive. However, your usage has lots of problems. You don't use DataReaders and DataSets with EntitySpaces. Below is an example of how you would load an entity in VB

     

    Code:
    Dim entity As Employees = New Employees()
    If entity.LoadByPrimaryKey(101) Then
     'Do Something
    End If
    
    Have a look at our Quick Reference for some code samples of basic operation. There is also a Getting Started pdf file under the EntitySpaces program file entry that has some helpful information when just getting started with EntitySpaces.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  04-07-2008, 3:02 PM 8762 in reply to 8760

    Re: Troubleshooting connection issues

    Thenk you very much.  It turns out the provider was case sensitive.

     It seems to me that the following line should have fired an exception if the Connection.Provider was invalid:

    Code:
    1    EntitySpaces.Interfaces.esConfigSettings.ConnectionInfo.Connections.Add(conn)
    

     

    I'll post that in the feature request thread.

    As for the usage issues... The reason I included the datareader was part of troubleshooting.  The fact that the datareader worked ruled out the connectionstring being the problem.

    Thanks again,

    Rob Hudson
    MyDistrict.Net


    There are 10 kinds of people in the world... Those who understand binary, and those who don't.
View as RSS news feed in XML