The EntitySpaces Community

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

[RESOLVED] Debugging a Run Time Error with Entity Spaces and MySQL

Last post 03-13-2008, 9:45 AM by David.Parsons. 3 replies.
Sort Posts: Previous Next
  •  03-11-2008, 12:29 PM 8382

    [RESOLVED] Debugging a Run Time Error with Entity Spaces and MySQL

    MyGeneration 1.2.0.7
    MySQL 5.0.51
    Entity Spaces 2007

    We have a production site working with Entity Spaces and SQL Server. I have been tasked with evaluating a change of database engines to MySQL. I've run into an issues with my tests.

    I have successfully generated both the Generated and Custom Classes using the MyGeneration Tool.

    The following code errors out on line 4 :

    Code:
    1    Protected Sub btnES_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnES.Click
    2            InitializeEntitySpaces()
    3            Dim it As New BusinessObjects.Item
    4            If it.LoadByPrimaryKey(356776) Then
    5                Me.GridView2.DataSource = it
    6                Me.GridView2.DataBind()
    7            End If
    8        End Sub
    9    
    10       Public Shared Sub InitializeEntitySpaces()
    11           '// Manually register a connection
    12           Dim conn As New EntitySpaces.Interfaces.esConnectionElement
    13   
    14           conn.ConnectionString = "Database=wires_dbo;Data Source=127.0.0.1;User Id=root;Password=notgoingtotell;"
    15           conn.Name = "Live"
    16           conn.Provider = "EntitySpaces.MySqlClientProvider"
    17           conn.ProviderClass = "DataProvider"
    18           conn.SqlAccessType = EntitySpaces.Interfaces.esSqlAccessType.DynamicSQL
    19           conn.ProviderMetadataKey = "esDefault"
    20   
    21           '// Assign the Default Connection
    22           EntitySpaces.Interfaces.esConfigSettings.ConnectionInfo.Connections.Add(conn)
    23           EntitySpaces.Interfaces.esConfigSettings.ConnectionInfo.Default = "Live"
    24       End Sub
    25   
    26   End Class
    
    The specific error is a NullReferenceException: Object Reference not set to an instance of an object.
    Code:
       at EntitySpaces.Interfaces.esDataProvider.esLoadDataTable(esDataRequest request, esProviderSignature sig)
       at EntitySpaces.Interfaces.esDynamicQuery.Load()
       at MySQLTestBench.BusinessObjects.esItem.LoadByPrimaryKeyDynamic(Int64 itemID) in C:\Documents and Settings\Ted Atchley\My Documents\Visual Studio 2005\Projects\MySQLTestBench\MySQLTestBench\DAL\Generated\Item.vb:line 127
       at MySQLTestBench.BusinessObjects.esItem.LoadByPrimaryKey(Int64 itemID) in C:\Documents and Settings\Ted Atchley\My Documents\Visual Studio 2005\Projects\MySQLTestBench\MySQLTestBench\DAL\Generated\Item.vb:line 97
       at MySQLTestBench._Default.btnES_Click(Object sender, EventArgs e) in C:\Documents and Settings\Ted Atchley\My Documents\Visual Studio 2005\Projects\MySQLTestBench\MySQLTestBench\Default.aspx.vb:line 26
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)"
       I've searched forums over and found similar cases but those are several months old. One solution mentioned an EntitySpaces.Loader method that is not in the current version of EntitySpaces that I have.
    I've verified the connection string by using ADO.net to make a connection
    Code:
    Dim strselectitems As String = "SELECT * FROM ITEM"
            Dim connstring As String = "Data Source=127.0.0.1;Database=wires_dbo;Uid=root;Pwd=notgoingtotell;"
            Dim daitems As New MySql.Data.MySqlClient.MySqlDataAdapter(strselectitems, connstring)
            Dim dsitems As New DataSet
            Dim cmdselect As New MySql.Data.MySqlClient.MySqlCommandBuilder(daitems)
            daitems.Fill(dsitems)
            Me.GridView1.DataSource = dsitems
            Me.GridView1.DataBind()

     

    That code works as expected.

    I would appreciate any advice you might have on debugging this. If I've missed an obvoius thread that contains a solution, I would request you give me a link to it.

    Thanks in advance for your time and attention.

    Filed under: ,
  •  03-11-2008, 2:50 PM 8385 in reply to 8382

    Re: Debugging a Run Time Error with Entity Spaces and MySQL

    Sorry... Since I do not see anything obviously wrong, this is long on questions, and short on answers.

    1. Do you have one of the Loaders registered in your app? I do not see it in your InitializeEntitySpaces() method.
    2. Which version of MySQL Connector/Net are you using?
    3. Which version of ES2007 are you using. You can find out by opening one of the files in your Generated folder, and looking at the header comments.
    4. Is your goal to replace the SQL Server back-end with the MySQL back-end, or do you plan to support both with EntitySpaces Multi-Provider capabilities?
    5. Have you seen the FAQ in our MySqlClientProvider forum?
    6. Do you have EntitySpaces.MySqlClientProvider.dll in your \bin folder?

     


    David Neal Parsons
    www.entityspaces.net
  •  03-13-2008, 6:06 AM 8402 in reply to 8385

    Re: Debugging a Run Time Error with Entity Spaces and MySQL

    1. I do not have any loaders.

    2. Connector is 5.2.1

    3. ES 2007.0.0528.0

    4. If our evaluation find that MySQL is viable for our business, we plan a full back end switch

    5. Yes.

    6. The dll is in the bin folder of my project.

    As an aside, we have been using ES successfully in our project (with our SQL Server backend) for quite some time without any loader object.

    I have added the loaded per the instructions in the "Getting Started" PDF. Now the error is a "FileNotFoundException. Could not load file or assembly 'MySql.Data, Version=5.0.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified. 

    My next step was to copy the MySQL.Data from the C:\ProgramFiles\MySQL\MySQL Connector Net 5.2.1\Binaries\.Net 2.0\ folder to the bin folder of my solution.

    This changed the error again.

    Now the error is a "FileLoadException. Could not load file or assembly 'MySql.Data, Version=5.0.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

    Searching on this error brougth me to this thread: http://community.entityspaces.net/forums/thread/1441.aspx which lead me to http://aspadvice.com/blogs/ssmith/archive/2006/11/15/AssemblyBinding-in-Web-Config-and-XMLNS.aspx.

    I will continue to update this response as I discover new information.

    So I added the runtime tags to my Web.config.

    Code:
    1     </system.web>
    2      <runtime>
    3        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    4          <dependentAssembly>
    5            <assemblyIdentity name="MySQL.data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
    6            <bindingRedirect oldVersion="5.0.0.0-5.0.4.0"
    7          newVersion="5.2.1.0"/>
    8          </dependentAssembly>
    9        </assemblyBinding>
    10     </runtime>
    11   </configuration>
    Code:
    1    Protected Sub btnES_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnES.Click
    2            InitializeEntitySpaces()
    3            Dim it As New BusinessObjects.Item
    4            If it.LoadByPrimaryKey(356776) Then
    5                Me.GridView2.DataSource = it
    6                Me.GridView2.DataBind()
    7            End If
    8        End Sub
    
    Now instead of failiing on line 4, it fails on line 5. Progress! 
    And the error has changed again.
    I get an InvalidOperationException when I try to assign the BusinessObject as a Datasource to a GridView. "Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource."

    Then I realized I was loading up a single record and decided instead to load up a collection.

    Code:
    1    Protected Sub btnES_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnES.Click
    2            InitializeEntitySpaces()
    3            Dim its As New BusinessObjects.ItemCollection
    4            its.Query.Where(its.Query.Color.Equal("32W"))
    5            If its.Query.Load Then
    6                Me.TextBox1.Text = its.Count
    7                Me.GridView2.DataSource = its
    8                Me.GridView2.DataBind()
    9            End If
    10       End Sub
    

    Badaboom, Badabing! It works.

    Hopefully my posting here will be of assistance to someone else in the future.

  •  03-13-2008, 9:45 AM 8404 in reply to 8402

    Re: Debugging a Run Time Error with Entity Spaces and MySQL

    Thanks for the thorough follow-through. Your post could save someone considerable time and effort. Yes And, your tenacity sure made my job a lot easier Big Smile
    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML