karlD
karlD

Reputation: 1

How can SQLAnywhere's "external CLR" access a System Process

In need of an extension in SQLAnywhere (16) to access some DOS functions on the server where the DB is running, I tried :

A first code for a DLL to be called from Sybase

________! SAExternal.vb !____________

Imports System.Diagnostics  

Public Class SAExternal  
    Public Shared Function getDone()
        Dim myProcess As Process = System.Diagnostics.Process.Start("notePad.exe", "C:\data\CLR\zTest.txt")  

        myProcess.WaitForExit()  
        myProcess.Close()  

        getDone = "OK"  
    End Function  
End Class

compiled using :
vbc.exe /t:library /out:SAExt.dll SAExternal.vb

Follows some code to test my DLL

_________! SAMain.vb !______________

Module SAMain  

    Sub Main()  
        Dim obj as New SAExternal()  

        MsgBox("Test SAMain " & obj.getDone())  
    End Sub  

End Module  

compiled using : vbc.exe /t:winexe /r:SAExt.dll SAMain.vb

SAMain.exe opens correctly notepad.exe, waits until I close it, and comes with the message "Test SAMain OK"

In SQLAnywhere, I coded :

CREATE FUNCTION getDone() 
RETURNS LONG VARCHAR
EXTERNAL NAME 'C:\data\CLR\SAExternal\SAExt.dll::SAExternal.getDone() string' 
LANGUAGE CLR

Calling the function by "Select getDone()" returns an error : "Impossible to load the file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=........' or one of it's denpendencies..."

If I take out the Process part of the SAExternal module:

Public Class SAExternal
    Public Shared Function getDone()
        getDone = "OK"
    End Function
End Class

my function gives me the correct answer ("OK")

For test purposes, I leaved all these files in the same directory as my Database file, including .vb and .dll .

I've searched the web for days to understand what I did wrong, and can't find what I missed.

Could somebody help me ?

Upvotes: 0

Views: 73

Answers (1)

gg89
gg89

Reputation: 380

try

CREATE FUNCTION getDone() RETURNS LONG VARCHAR
EXTERNAL NAME 'C:\data\CLR\SAExternal\SAExt.dll::SAExternal.getDone() *out* string' 
LANGUAGE CLR

Please notice the addition of the out option before string

Upvotes: 0

Related Questions