Finding IP Address and Connecting Microsoft SQL Server By Using Microsoft Visual Foxpro

This technique only demonstrates how to detect internet protocol address connected to our computer network by using Visual Foxpro. It’s not to attempt to use Microsoft SQL server database in manipulating database table as well, but it’s possible if you would like to modify MS-SQL in Visual Foxpro script program. For the beginner in programming, it is not so difficult to follow and you could develop it as you wish. I will not exploit SQL server script since it can be used in other language computer programs.

All of the script below had been tested in computer network (by using ip address number) or you could examine for pinging world wide web address as well. The last script in this article is the most important thing if you would like to learn about Visul Foxpro Library. I suggest you to read deeply the manual given by Microsoft.

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. A small modification of the script could be tried in finding some IP addresses. You can 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

The last result of the script is “test.txt” in which the result would display whether the ip address connected or not. Thus, 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 J.

The second stage, you can ignore it if you don’t like, we attempt to connect MS-SQL Database Server. As a result, there are second step in connecting MS-SQL server database, firstly, detecting ip server address 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 you ip address undetected. By detecting ip address 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= {SQLServer};server=”+ipServer+”;dsn=”+dsnName+”;database=”+DataBaseName+”;uid=sa;pwd=”
DBConn=SQLSTRINGCONNECT(LcConn)
IF DBConn < 0
?’Connection failed’
RETURN .F.
ELSE
SQLText=”<SQL SCRIPT>”
xx=SQLEXEC(DBConn,SQLText)
=SQLDISCONNECT(DBConn)
ENDIF
ENDIF
SELECT SERVER
SKIP
LOOP
ENDDO

The simplest thing that you can do in finding IP Address is by using win32_pingstatus class provided by Microsoft. Win32_pingstatus represents ping standard command but, unfortunately, it does not work in Windows 2000 and Windows NT Server. You could modify the simple script syntax below in trying ping command in Visual Foxpro.

Local vWM, vAddr, vPinging, vPing, vNetCon
vAddr = “192.168.1.1″
vWinS = createobject(“MSWinsock.Winsock”)
YourComputerIpAddress=vWinS.LocalIP
vPinging = vWMI.ExecQuery([Select * from WIN32_Pingstatus where address='] + vAddr + ['])
for each vPinging in vPing
if vNetConn>0
messagebox(“ IPAddress 192.168.1.1 “+vNetStatus+” “,16,0)
vNetConn=0
return
endif
next

Modification of the script above could be done, particularly in using SQL script in manipulating your transaction table. Please notify that I use Microsoft SQL server 2000 and Microsoft Visual Foxpro V9 in demonstrating the script.

Best.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.