Article ID: 191867
Article Last Modified on 2/16/2005
connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<strong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
TEST=SQLEXEC(gnConnHandle,'select @@version','getversion')
SELECT getversion
versioninfo=EXP
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIF If you are connecting to SQL Server 7.0 or later, use this code
connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<stong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
TEST=SQLEXEC(gnConnHandle,'select @@version','getversion')
SELECT getversion
versioninfo=STRCONV(exp,10) && Convert Unicode to UTF-8
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIFDO SQLVERS1
connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<strong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
TEST=SQLEXEC(gnConnHandle,'exec xp_msver','getversion')
SELECT getversion
versioninfo=EXP
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIFIf you are using SQL Server 7.0 or later, use this code:
connection_string='DRIVER={SQL Server};SERVER=<server name>;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<Strong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
TEST=SQLEXEC(gnConnHandle,'exec xp_msver','getversion')
SELECT getversion
versioninfo=STRCONV(exp,10) && Convert Unicode to UTF-8
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIFDO SQLVERS2
connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<strong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
sqlcommand="SELECT version FROM sysdatabases WHERE dbid = 1"
TEST=SQLEXEC(gnConnHandle,sqlcommand,'getversion')
SELECT getversion
versioninfo=EXP
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIF If you are using SQL Server 7.0 or later, use this code:
connection_string='DRIVER={SQL Server};SERVER= <server name>;' + ;
'DATABASE=PUBS;UID=<user name>;PWD=<strong password>'
gnConnHandle=SQLSTRINGCONN(connection_string)
IF gnConnHandle>0
sqlcommand="SELECT version FROM sysdatabases WHERE dbid = 1"
TEST=SQLEXEC(gnConnHandle,sqlcommand,'getversion')
SELECT getversion
versioninfo=STRCONV(exp,10) && Convert Unicode to UTF-8 &&EXP
sqldisconn(gnConnHandle)
=MESSAGEBOX(versioninfo,48,"SQL Server Version")
ELSE
=MESSAGEBOX("Connection Failed",16,"ODBC Problem")
ENDIFDO SQLVERS3
Keywords: kbhowto kbsqlprog kbcode KB191867