Toad World® Forums

How to call Toad Data Modeler from C# application?

I generated a TXP model using Toad Data Modeler 6.1
I launched the command: TDM.exe /regserver
I written and executed automation script to perform various Toad Data Modeler tasks.

How to call TDM from C# application? I tried to execute the following csharp code:

{

Type toadType = System.Type.GetTypeFromProgID(“TDM.App”);
dynamic App = System.Activator.CreateInstance(toadType);

while (!App.Application.IsPackagesLoaded)
{
Thread.Sleep(1000);
}

var Model = App.OpenModelFromFile(“C:\MyProject.txp”);

// TO DO…

}

but The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).

How can I solve this problem, anyone knows? Thanks very much!

Regards,
Nicola

Hello Nicola,

could you provide fully version number? (6.1 can be 32b, 64b, Full or Freeware).

I tried only calling from JScript(I don’t have C#) on TDM 6.1.3.26 and it is works. It can be same as C#. Did you try some simple JScript? I attached one example(need to change path to model and output folder in it).

On which line is exception raise?

Daril
generaterep6.zip (619 Bytes)

Hi Daril, Thank you so much for your help.

I also tried calling from JScript on TDM 6.1.4.4 (Freeware, 64 bit) and it is works. I’m trying to create an Automation Client for Toad in C#, not in Jscript o VBScript. When i execute c# code written previously, the server threw an exception on the third line “while (!App.Application.IsPackagesLoaded)”. In your opinion, is it possible?

Regards,

Nicola

Hi Nicola,

My colleague ,who works in C#, test to us simple calling of TDM from C# code. See sample

{

  Type toadType = System.Type.GetTypeFromProgID("TDM.App");

  if (toadType != null)

  {

    try

    {

      dynamic App = System.Activator.CreateInstance(toadType);

      if (App != null)

      {

        **toadType.InvokeMember("Hello", BindingFlags.InvokeMethod | BindingFlags.Public, null, App, null);**

        Console.WriteLine("DONE");

      }

      else Console.WriteLine("Instance is null");

    }

    catch(Exception ex)

    {

      Console.WriteLine(ex.Message);

    }

  }

  else Console.WriteLine("TDM.App not found");

  Console.ReadLine();

}

It’s look like you need use InvokeMember method. In example it is use simple TDM function Hello, it get dialog with TDM version.

Daril