none
C# DLL and System.Data.SqlClient error 0x8007001f AddNativeTimer RRS feed

  • Question

  • I wrote a DLL in C# that I exported the functions using C++/CLI.  It works perfect if I run it via RunDLL32.  If I run it in another native application, I get an error when I try to open a database connection.

    Hresult: 0x8007001f  And a bunch of stuff about System....AddTimerNative, linked all the way back to opening the connection.  Even executeNonQuery errors out.

    This works as a DLL in windows XP (32), and sometimes works on Windows 7.  

    Here is the code that crashes with that error:

    public static bool RunE(string arg)
            {
                try
                {
                    using (SqlConnection conn = new SqlConnection(connstring))
                    {
                        conn.Open();
                        //throw new System.Exception(Query);
                        using (SqlCommand cmdGet = new SqlCommand(arg, conn))
                            cmdGet.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message.ToString() + e.StackTrace.ToString());
                    return false;
                }
                return true;
            }

    And the code that calls it:

    [STAThread]

            public static int ExtDoQueue(int someval) //Exported
            {
                SQL.RunE("Select 1");

           }

    And the C++ that calls this:

    extern "C" __declspec(dllexport)
    int test() {
    Program::ExtDoQueue(0);
    return 0;
    }

    And the Delphi 6.0 that calls that:

    procedure ViewQueue(caller: tform);

    begin
      CheckCreports;  //This makes sure hm is loaded via load library
      try
        if (@ExtDoQueue = nil) then @ExtDoQueue := GetProcAddress(hm, 'test');
        ExtDoQueue(0);
      except
       on e: Exception do
          gLogger.LogError('CREPORT ERROR - DoQueue: ' + e.Message + ' ' +
            inttostr(GetLastError));
      end;

    end;

    And the rundll that works..........

    Rundll32 myDll.dll,TechMenu

    And the code for TechMenu merely calls doQueue, chaining another function had no effect, if you were thinking that.

    I'm thinking that database access isn't going to work inside this DLL.  It's just highly unstable and the code has ran fine for about a year as a separate exe file, but I wanted more integration so I made a DLL out of it.

    I tried unmanaged exports direct from C#, (round tripping IL(D)ASM) and I got the exact same results.  So I made a C++/CLI warpper. Same thing.  Made another exe and connected the two program via named pipes - fine, but I can't get modal dialogs to block other application. (Dialogs are in the DLL/EXE).

    I'm not sure where to go with this error, it's really making me insane.

    Any insight?

    Thursday, October 11, 2012 4:54 PM

All replies

  • Hi trellend

    Am I understanding correctly that you cannot see the popup message with the actual errormessage and stacktrace?

    If you can, can we please see that detail?

    If you can not, please try NOT to catch the exception and NOT show the messagebox, and let the error bubble back to the calling application, perhaps you can see the exception detail from there? And show it here please?

    What is the format of the connection string you use? Are you using a username and password? Or are you using a windows user account with the "integrated security" option?

    Another thing to consider, is that the RunE() method uses ExecuteNonQuery() while the calling app needs a ExecuteQuery() for the "select" statement.

    Let me know what you find.

    Thursday, October 11, 2012 5:39 PM
  • I doesn't matter what you put in the SQL.  I did select 1 to rule out anything else.   The normal one uses a datareader and some delegate callbacks.  Tried to simplify things for here.

    If I put up a small sample project for MSVC# and MCVC++ 2010 that reproduces the error on Windows 7 will you try it?


    Friday, October 12, 2012 4:11 PM
  • I gave up.

    Even a small test program fails miserably as a DLL.  I went with 2 apps and named pipes to communicate.  Works.


    ...

    Sunday, October 14, 2012 11:00 PM