Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check for connection
Message
From
23/04/2004 22:20:45
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00897480
Message ID:
00897847
Views:
17
Hi Borislav


This is what i do....
my main.prg
parameters maindata,mainserver
set talk 
set exclu
set data
.
.
.
set proc to mproc.prg
public myhandle


so whenever i need connection

myhandle = myconnect()
if myhandle > 0
   inhandle = sqlexec(myhandle,'select *.....','mydata')
    if inhandle = 1
        do.....
    else
        messagebox("Connection to server fail...please retry",0,"Warning")
        myhandle = -2
    endif
else
    messagebox("Connection to server fail...please retry",0,"Warning")
    myhandle = -2
endif


mproc.prg
Function myconnect()
Local sqlhandle,mstring,lcchkfile,gnend,gntop,gnfilehandle,mstring,lctext,lcposition,lcerror
sqlhandle = 0
lcerror = .F.
If (Empty(mainserver) .Or. Vartype("mainserver") = "U") .Or. (Empty(maindata) .Or. Vartype('maindata') = 'U')
	gnfilehandle = Fopen('server.txt',10) && this way i put my server name and the database name i need to connect to
	If gnfilehandle < 0
		=Messagebox("Server Cannot be Found...Pls contact your admin",0,"Warning")
		lcerror = .T.
	Else
		Store Fseek(gnfilehandle, 0, 2) To gnend    && Move pointer to EOF
		Store Fseek(gnfilehandle, 0) To gntop     && Move pointer to BOF
		If gnend <= 0  && Is file empty?
		=Messagebox("Server Cannot be Found...Pls contact your admin",0,"Warning")
			lcerror = .T.
		Else  && If not
			lctext = Alltrim(Fgets(gnfilehandle,gnend))
			lcposition = Atc(",",lctext)
			If lcposition > 0
				mainserver = Alltrim(Substr(lctext,1,lcposition-1))
				maindata = Alltrim(Substr(lctext,lcposition+1))
				lcerror = .F.
			Else
		=Messagebox("Server Cannot be Found...Pls contact your admin",0,"Warning")
				lcerror = .T.
			Endif
		Endif
	Endif
	=Fclose(gnfilehandle)
Endif
If lcerror = .F.
	mstring = "driver={SQL Server};server="+mainserver+";uid=sa;pwd=kan67;database="+maindata
	Wait Window "Please Wait .... Trying To Connect To Server" Nowait Noclear
	sqlsetprop(0,"DispWarnings",.F.)
	sqlsetprop(0,"DispLogin",3)
	sqlhandle = Sqlstringconnect(mstring)
	Wait Clear
Else
	sqlhandle = -2
Endif
Return sqlhandle
Endfunc
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform