Dimension mylogin (4) & define an array
Mylogin (1) = alltrim (thisform. text2.value) & server address, for example: 192.168.1.188
Mylogin (2) = alltrim (thisform. text4.value) & database name, for example: mydata
Mylogin (3) = alltrim (thisform. text3.value) & SQL query username example: SA
Mylogin (4) = alltrim (thisform. text1.value) & SA Password
Public nygxx & define global variables, connection handle
Nygxx = sqlstringconnect ('driver = SQL Server; server = & mylogin (1 ).; uid = & mylogin (3 ).; pwd = & mylogin (4 ).; database = & mylogin (2 ). ') & get the variable value through &
If! Empty (alltrim (mylogin (1) and! Empty (alltrim (mylogin (2 )))
If nygxx> 0
# Define odbc_add_dsn 1 & create if no DSN exists
# Define odbc_config_dsn 2 & reconfigure if DSN exists
# Define odbc_remove_dsn 3 & Delete the DSN if an error occurs
Declare integer sqlconfigdatasource in odbccp32; & call an API Function
Integer hwndparent ,;
Integer frequest ,;
String lpszdriver ,;
String lpszattributes
Pcdriver = 'SQL Server'
Pcserver = mylogin (1)
Pcdatabase = mylogin (2)
Pcuid = mylogin (3)
Pcpwd = mylogin (4)
Pcaccid = NULL
Pcuserid = NULL
Lpszdriver = pcdriver
Hwndparent = NULL
Lpszattributes = "Server =" + alltrim (pcserver) + CHR (0) +;
"Description = powerdsn" + CHR (0) +;
"DSN = mydsn" + CHR (0) + "database =" + alltrim (pcdatabase)
Nreturn = sqlconfigdatasource (0, odbc_config_dsn, lpszdriver, lpszattributes)
If nreturn = 0
Mreturn = sqlconfigdatasource (0, odbc_add_dsn, lpszdriver, lpszattributes)
If mreturn = 0
Clear DLLs
Endif
Else
Clear DLLs
Endif
Else
MessageBox ('network connection failed. Check whether the network, server address, or database is correct ', 48, 'infos ')
Endif
Else
If MessageBox ("the option cannot be blank for the server or database", 48 + 4, "Operation prompt") = 6
Return
Else
Quit
Clear events
Endif
Endif