|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 191867 - Last Review: February 16, 2005 - Revision: 4.4 How to obtain SQL Server version information from Visual FoxProThis article was previously published under Q191867 Information regarding the versions of Microsoft SQL Server
can be useful when you are writing commands that are intended to be specific to
a particular version of SQL Server. To check for version
information, use one of the following methods:
- Use the "@@version" global variable.
- Use the "xp_msver" extended stored procedure.
- Query the version column of the sysdatabases
table.
All of these methods return the same information. This article
describes how to obtain the SQL Server version information from within Visual
FoxPro. Example one The first example illustrates the use of SQL Server's @@version
global variable to obtain SQL Server versioning information. Note You must change UID <username> and
PWD <strong password> to the correct values before you run this code. Make
sure that UID has the appropriate permissions to perform this operation on the
database. - Create a program file named Sqlvers1.prg that contains the
following code:
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")
ENDIF - From the Command window, type the following command:
DO SQLVERS1
Example two The second example illustrates the use of SQL Server's xp_msver
extended stored procedure to obtain SQL Server versioning information.
- Create a program file named Sqlvers2.prg that contains the
following code:
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")
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
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")
ENDIF - From the Command window, type following command:
DO SQLVERS2
- Compare the output with the information that you obtained
using the @@version global variable.
Example three The third example illustrates the use of information contained in
the version column of the sysdatabases table to obtain SQL Server version
information.
- Create a program file named Sqlvers3.prg that contains the
following code:
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")
ENDIF - From the Command window, type the following command:
DO SQLVERS3
- Compare the output with the information that you obtained
using the @@version global variable and the xp_msver extended stored
procedure.
APPLIES TO- Microsoft Visual FoxPro 3.0b for Macintosh
- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft Visual FoxPro 3.0b Standard Edition
- Microsoft Visual FoxPro 5.0 Standard Edition
- Microsoft Visual FoxPro 5.0a
- Microsoft Visual FoxPro 6.0 Professional Edition
- Microsoft Visual FoxPro 7.0 Professional Edition
- Microsoft Visual FoxPro 8.0 Professional Edition
- Microsoft Visual FoxPro 9.0 Professional Edition
| kbcode kbhowto kbsqlprog KB191867 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |