Here is the situation.

I have a remotable component that implements Open/Close and Method.
Open and Close are respectively Opening and Closing the DB connection.
Method is just accessing the DB via the DB connection reference.
The DB Connection object is private to the component.
When invoking the Method (after Open) via the static Main, it works fine;
When invoking the Method (after Open) via a remote client, even if the Open
succeeds, the Method fails with a reference problem on the DB Connection
object.
The simple project to reproduce is at http://mysqlpb.free.fr.
See parts of the component code here;

My guess is that the DB Connection object has probably to be declared
specifically in order to not be involved with Marshalling or so.

For sure, as a work around, this works fine when all the DB work is
performed via a local DBAccessor (implemented external to the remotable
component). I just would like to understand the issue here.

Thanks in advance for your help

<CODE>

using System;
...

using ByteFX.Data.MySQLClient;

namespace ConsoleApplication
{
 public interface IMyInterface
 {
  void MyMethod(String str);
 }

 public class App
  : System.ComponentModel.Component
  , IMyInterface
 {
  public MySQLConnection dbc;

  public App()
  {
   InitializeComponent();
  }

  [STAThread]
  static void Main()
  {
   App svr = new App();

   svr.Open();

   IMyInterface p = svr;

   p.MyMethod("Called locally - should be OK");

                        <.Net Remoting Listener code here ...>

   Console.ReadLine();

   svr.Close();
  }

                < Dispose code here ... >
                < InitializeComponent code here ... >

  // Service

  private String DataSource = "localhost";
  private String Database  = "database";
  private String UserID  = "administrator";
  private String Password  = "password";

  void Open()
  {
   Console.WriteLine();
   String temp = String.Format("The server is
started");
   Console.WriteLine(temp);
   try
   {
    String dbcs = String.Format
     ( "Data Source={0};Database=
{1};User ID={2};Password={3}"
     , DataSource
     , Database
     , UserID
     , Password
     );
    dbc = new MySQLConnection(dbcs);
    dbc.Open();

    Console.WriteLine(String.Format("DB
Connection State in OnStart : {0}",dbc.State.ToString()));
   }
   catch(MySQLException ex)
   {
    String err = String.Format("The server
failed to open the DB connection\n Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
   catch(System.Exception ex)
   {
    String err = String.Format("The server
failed to open the DB connection\n System Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
  }
  void Close()
  {
   String temp = String.Format("The server is
stopped");
   Console.WriteLine(temp);
   Console.WriteLine();
   try
   {
    dbc.Close();
   }
   catch(MySQLException ex)
   {
    String err = String.Format("The server
failed to close the DB connection\n Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
   catch(System.Exception ex)
   {
    String err = String.Format("The server
failed to close the DB connection\n System Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
  }

  // IMyInterface

  void IMyInterface.MyMethod(String str)
  {
   Console.WriteLine();
   String temp = String.Format("MyMethod : {0}",str);
   Console.WriteLine(temp);
   try
   {
    Console.WriteLine(String.Format("MyMethod:
DB Connection State in OnStart : {0}",dbc.State.ToString()));
   }
   catch(MySQLException ex)
   {
    String err = String.Format("The server
failed in MyMethod\n Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
   catch(System.Exception ex)
   {
    String err = String.Format("The server
failed in MyMethod\n System Exception: {0}",ex.Message);
    Console.WriteLine(err);
   }
  }
 }
}

</CODE>

Reply via email to