on 2020 Oct 15 3:42 AM
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!!" ; } } }
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!');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
62 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.