cancel
Showing results for 
Search instead for 
Did you mean: 

Sybase 17 call External DLL, Could not find --'MyMethodTEst' in dynamic library..

0 Kudos
1,542

I created a simple DLL in C# (using Visual Studio 2017) and I'm trying to call it from a stored procedure in Sybase 17.

When I call the Store Procedures, I received an error message saying that method could not be found in the DLL. It looks like the methods inside the DLL is not visible outside?!

Sybase Procedures:

CREATE PROCEDURE "mystring"()
External name 'MyMethodTEst@c:\\\\D\\\\AmosTest.dll' language "C_ESQL64"

Call the store Procedure:

CALL "amos"."mystring"()

Sybase Error:

-- Could not execute statement. -- Procedure 'mystring' terminated with unhandled exception 'Could not find --'MyMethodTEst' in dynamic library 'c:\\D\\AmosTest.dll'' -- SQLCODE=-91, ODBC 3 State="HY000" -- (Continuing after error) -- Procedure completed

DLL Source code:

using System;
using System.Runtime.InteropServices;

namespace AmosTest {
    [ComVisible(true)]
    [ProgId("AmosTest.Class1")]
    public class Class1 {
        public string MyMethodTEst(string param) {
            return "OK!!" ;
        }
    }
}
VolkerBarth
Contributor

Your CREATE PROCEDURE statement would fit for a C/C++ external function, not for a CLR method. For native CLR functions and procedures you need to specify "LANGUAGE CLR", and the class name must be added, as well. Confine the sample from the docs.

0 Kudos

Thanks a lot for you feedback.

I Have modified the Store Procedure:

ALTER PROCEDURE mystring() external name 'Class1.MyMethodTEst@c:\\D\\AmosTest.dll' language CLR

BUT I've got this error:

CALL mystring()

-- Could not execute statement. -- Procedure 'mystring' terminated with unhandled exception 'Invalid method -- signature: 5AmosTest.Class1.MyMethodTEst@c:\\D\\AmosTest.dll' -- SQLCODE=-91, ODBC 3 State="HY000" -- (Continuing after error) -- Procedure completed

Any Idea? Thanks again in advances. Ale

VolkerBarth
Contributor
0 Kudos

Can't tell whether the path/location is correct, however, AFAIK all CRL methods must be declared static when called from SQL Anywhere, cf. the samples.

In other words: I'd recommend to try to run a given sample - and once that does work, try my own approaches...

0 Kudos

Hi Volker

First of all thanks again, now I fixed, the problem was the .NET project. I create a new project in c# and not in C++ and now when I Compile the DLL it works fine. Thanks again for your help!

Accepted Solutions (0)

Answers (1)

Answers (1)

chris_keating
Product and Topic Expert
Product and Topic Expert

The functions have to be declared static and your external procedure definition is declared incorrectly as it is not being supplied a parameter ( and should really be a function since you are returning a value). That said, the key issue for the error is that the method is AmosTest.Class1.MyMethodTEst (the namespace, class, and method).

The correct C# code is:

using System.Runtime.InteropServices;

namespace AmosTest {
    [ComVisible(true)]
    [ProgId("AmosTest.Class1")]
    public  class Class1 {
        public static string MyMethodTEst(string param) {
            return "OK!!" ;
        }
    }
}

And the function in SQL Anywhere should be:

create or replace function mystring( in c long varchar ) 
    returns long varchar 
        external name 'AmosTest.dll::AmosTest.Class1.MyMethodTEst(string) string' 
    language clr;

And called like:

select mystring('Hi!');