Hello together,
I want to replace a VFP project with a SOAP connection to the DBF tables with a REST API connection to an MS SQL Server.
I'm using West-Wind Web Connection for this.
Are there any suitable examples I could use as a basic framework?
Step by Step: Creating a JSON REST Service
As a beginner in setting up a REST API server, I've already worked through this chapter.
Unfortunately, it doesn't include any examples of how to access the SQL server, for example, using the wwSQL class.
So far, I haven't found out whether this class can read the connection string directly from a configuration XML file.
My question is, where in the code should I create the wwSQL class, and can I read the connection string via a wwSQL method?
You should set up wwSql in your server startup. There's an oSQL property on your wwServer instance and you can read the configuration information there. You can create a connection string in the server configuration files (yourApp.ini).
There are examples of this in the default installer and I believe in the generated classes in the Load() method do this but it's commented out by default.
Something like this:
*** Load up any SQL Connections
#IF WWC_USE_SQL_SYSTEMFILES
THIS.oSQL = CREATE("wwSQL")
IF !THIS.oSQL.Connect(THIS.oConfig.cSQLConnectString)
MESSAGEBOX("Couldn't connect to system SQL Service. Check your SQL Connect string",48,"Web Connection")
CANCEL
ENDIF
this.oSql.EnableUnicodeToAnsiMapping(.T.)
#ENDIF
You can remove the conditional around the code to always have it work.
Read up on how the configuration handling works. You can create multiple connections and multiple configuration values for each connection if necessary but you'll need to add any other sql instance configuration settings explicitly.
To use you can then use:
*** In a Process method
lnRecs = Server.oSql.Execute("select * from customers")
+++ Rick ---