This technique only demonstrates how to detect internet protocol address connected to our computer network by using Visual Foxpro. It does not attempt to use Microsoft SQL server database in manipulating table but you can modify using MS-SQL script in it. For the beginner in programming, it is not so difficult to follow and you can develop it, as you wish. I will not exploit SQL server script since it can be used in other language computer programs.
ipServer = "192.168.7.101" &&& or “www.kompas.com”
msDosCmd= "%comspec% /c ping " +ipServer+ " -n 1 > test.txt"
loWshShell = CREATEOBJECT("WScript.Shell")
loWshShell.RUN(msDosCmd, 0, .T.)
DocPing=filetostr("test.txt")
=MESSAGEBOX(DocPing)
It detects only a single ip address: 192.168.7.101. We can use the script if we would like to detect some computer connected to our computer network. You can use the script below to detect computers connected to you computer since you know ip address number in your computer network.
DO WHILE !EOF()
ipServer=xxipServer
msDosCmd = "%comspec% /c ping " + ipServer + " -n 1 > test.txt"
loWshShell = CREATEOBJECT("WScript.Shell")
loWshShell.RUN(msDosCmd, 0, .T.)
IF SUBSTR(FILETOSTR("test.txt"),274,1)='0'
?ServerName+’ connection failed’
ELSE
?ServerName+’ connected’
ENDIF
ENDDO
Result of the script is “test.txt” in which the result would display whether the ip address connected or not. It might be you can use another method in determining computer connection better than “substr(filetostr(‘xx’,274,1)=’0’” usage (!). You could miss some nodes, obviously, I can use it properly so far .
The second stage, you can ignore it as you wish, we attempt to connect MSSQL. As a result there are second step in connecting MS-SQL server database, firstly, detecting ip server and secondly, connecting to your database server. As I said above,”you can ignore it” because this step is wasting time when you were writing this script because you have to detect ip server and you also have to detect database server. The big question is: Is it possible to connect to our database server without detecting ip server? It could be, but the problem is you will take much longer when your database connection is failed. The computer would say nothing for a few second when your database server is broken or undetected. By detecting ip address first, we can ignore database server detection. When server connection is failed, it would be better if you ignore the second step directly. The best performance for this script is more than twenty node computer workstation. A hundred would be much better.
USE Server in 01 alias SERVER
...
DO WHILE !EOF()
DosCmd = "%comspec% /c ping " + ipServer + " -n 1 > test.txt"
loWshShell = CREATEOBJECT("WScript.Shell")
loWshShell.RUN(DosCmd, 0, .T.)
IF SUBSTR(FILETOSTR("test.txt"),274,1)='0'
?ServerName+" connection failed"
ELSE
LcConn="driver= {SQL Server};server="+ipServer+";dsn="+dsnName+";database="+DataBaseName+";uid=sa;pwd="
DBConn=SQLSTRINGCONNECT(LcConn)
IF DBConn < 0
?'Connection failed'
RETURN .F.
ELSE
SQLText=sqlscript
xx=SQLEXEC(DBConn,SQLText)
=SQLDISCONNECT(DBConn)
ENDIF
ENDIF
SELECT SERVER
SKIP
LOOP
ENDDO
You can try some modification based on the script above, particularly in using SQL script in manipulating your transaction table. As a small notice, I use Microsoft SQL server and visual foxpro V9.
Regards.