• Welcome, Guest. Please login.
 
October 21, 2019, 02:22:15 am

News:

Welcome to the SQLitening support forums!


Using Visual Studio to connect with SQLitening

Started by cheenu, May 06, 2016, 05:50:00 am

Previous topic - Next topic

cheenu

Hello !
I am seeking assistance from fellow members to help me understand and implement a c# program (which I am writing in Visual Studio framework).
I have been able to install SQLLitening, but I am not able to establish connection with the database. I want to know, how to connect to SQLLitening in Client-Server mode using C#.


cj

SQLiteningU.Bas was created to call routines from languages other than PowerBASIC.
Somebody that has already done this will hopefully step in.

You would probably get  results much sooner from the PowerBASIC forum on using with other languages.
This has come up and some searches here and at the PowerBASIC forum might help.


#========================<[ SQLitening API's ]>=========================
SQLitening comes with three different API's as follows:
   Basic     ---  Dll name is SQLitening.Dll
             ---  Include name is SQLitening.Inc
             ---  All routines begin with sl.
   Special   ---  Dll name is SQLiteningS.Dll
             ---  Include name is SQLiteningS.Inc
             ---  All routines begin with sls.
   Universal ---  Dll name is SQLiteningU.Dll
             ---  Include name is SQLiteningU.Inc
             ---  All routines begin with slu.

All DLL's are written in PowerBASIC and use the SDECL (aka STDCALL)
convention for parameter passing.  SDECL specifies that the declared
procedure uses the "Standard Calling Convention" as defined by Microsoft.
When calling an SDECL procedure, parameters are passed on the stack from
right to left and the stackl is automatically cleaned before execution
returns to the calling code.

PowerBASIC allocates strings using the Win32 OLE string engine.
This allows you to pass strings from your program to DLLs, or
API calls that support OLE strings.


   Which API or DLL should you use?

Basic:: Always try to use the Basic API.  If you language supports passing
OLE strings both ByVal and ByRef then you should be able to use the Basic
API.  OLE strings are allocated using the Win32 OLE string engine.  There
are some routines in the Basic API that will probably only work with
PowerBASIC.  slSelAry is one that passes an array and therefore may only
work in PowerBASIC.  You may need to modify the include file
(SQLitening.Inc) to support your language

Special:: If your language supports OLE string passing but only ByRef
(Visual Basic) then the Special API will probable work for you.  The
language must also support optional parameter passing.  The slSelAry is
not available in this API.  You will need to modify the include file
(SQLiteningS.Inc) to support your language This DLL is a front-end to the
Basic API.

Universal:: If your language does not support OLE strings then the Special
API will probable work for you.  This API will work for any language that
can call a standard Dll.  The parameter passing is patterned after the
Windows API.  The slSelAry is not available in this API.  You will need to
modify the include file (SQLiteningU.Inc) to support your language. This
DLL is a front-end to the Basic API.  Documentation about parameter passing
is located in the include file.


This is an example call to SqliteningU interface (if appropriate?)
Just describing that there are 3 interfaces and if none work we can write something that will.



'============================<[ Connect ]>=============================
DECLARE FUNCTION sluConnect LIB "SQLiteningU.Dll" ALIAS "sluConnect" (_
                                 BYVAL Server AS LONG, _
                                 BYVAL Port AS LONG, _
                                 BYVAL ModChars AS LONG, _
                                 BYVAL OutData AS LONG, _
                                 BYREF SizeOfOutData AS LONG) AS LONG
'   Server is a pointer to a null-terminated string.
'   ModChars is a pointer to a null-terminated string. If not needed you
'            may pass a zero.
'   DataOut is a pointer to the returning out data. If not needed you
'           may pass a zero.
'   SizeOfOutData is both passed and returned. Pass the size of OutData.
'                 It must be at least the size of the returning out data.
'                 The actual length of the returing out data is returned.
'                 If the passed size is too small then the returning length will
'                 be set to -1.



cj

Did you get everything working?

If not, let us know so another interface will be written.
If you don't own PowerBASIC the DLL will be created for you.
Any variation is possible: BYVAL, BYREF, OPTIONAL or passing a single string.

Writing a helper function that calls slConnect is simple.
The EXPORT is only needed if helper function is placed into a DLL.

This first example gets rid of the BYVAL's.

#INCLUDE "SQLitening.inc"
FUNCTION slConnec ALIAS "slConnec"( _
   OPTIONAL rsServer AS STRING, _
   OPTIONAL rlPort AS LONG, _
   OPTIONAL rsModChars AS STRING, _
   OPTIONAL wsOutData AS STRING) EXPORT AS LONG

  IF ISMISSING(rsServer)   THEN rsServerBYVAL    = "" ELSE rsServerBYVAL   = rsServer
  IF ISMISSING(rlPort)     THEN rlPortBYVAL      = 0  ELSE rlPortBYVAL     = rlPort
  IF ISMISSING(rsModChars) THEN rsModCharsBYVAL  = "" ELSE rsModCharsBYVAL = rsModChars
  IF ISMISSING(wsOutData)  THEN wsOutDataBYREF   = ""
  FUNCTION = slConnect(rsServerBYVAL, rlPortBYVAL,rsModCharsBYVAL,wsOutDataBYREF)
END FUNCTION



Example passing a string with IP,PortNumber separated with a comma.
IP_Comma_Port =  "192.168.1.2, 51234"

FUNCTION slConnection ALIAS "slConnection" (IP_Comma_Port AS STRING) EXPORT AS LONG
  LOCAL rsServer AS STRING
  LOCAL rlPort AS LONG
  IF PARSECOUNT(IP_Comma_Port) = 2 THEN
    rsServer = PARSE$(IP_Comma_Port,1)      'ip address
    rlPort =   VAL(PARSE$(IP_Comma_Port,2)) 'port number
    IF rlPort > -1 AND rlPort <65536 THEN
      FUNCTION = slConnect(rsServer, rlPort,"E0") '0 = success, no msgbox if error
    ELSE
      ? "Port number must be 0 to 65535",,"Out of range"
      FUNCTION = -998
    END IF
  ELSE
    ? "Syntax: result= slConnection(""192.168.1.2,51234"")",,"Invalid parameters"
    FUNCTION = -999
  END IF
END FUNCTION