The connection will be opened and closed automatically because the oSql object goes out of scope.LOCAL oSQL as wwSQL oSQL = CREATEOBJECT("wwSQL") ? oSql.Connect("driver={sql server};server=(local);database=webstore") oSql.execute("select * from wws_customers") RETURN
The following example demonstrates this sequence of events:
DO WCONNECT *** Make sure SQL is running CLOSE data oSQL = CREATEOBJECT("wwSQL") ? oSql.Connect("driver={sql server};server=(local);database=webstore") oSql.execute("select * from wws_customers") ? oSql.cErrorMsg WAIT WINDOW "Turn off SQL Server to test a connection failure" BROWSE *** Stop Sql Server - this will fail CLOSE DATA IF oSql.execute("select * from wws_customers where company like 'W%'") = -1 WAIT WINDOW "Connection failed: " + CHR(13)+ oSql.cErrorMsg + ; "Now Turn SQL Server back on" ELSE BROWSE ENDIF *** TURN SQL SERVer back on - this should work IF oSQL.Execute("select * from wws_invoice") = -1 WAIT WINDOW "Connection failed: " + CHR(13)+ oSql.cErrorMsg ELSE BROWSE ENDIF
There's nothing that that prevents failures of current SQL commands if a connection fails. So if the connection is failing wwSQL tries to reconnect once and then returns an error. The reconnection is meant to detect when a connection comes back up, so it's still vital that your code check result codes from all SQL commands to handle possibly retrieval failures.