JohnC JohnC - 1 year ago 52
SQL Question

How to determine SQL server version number for Compact edition 4 up to full sql server 2008?

Lot's of people have asked and been responded to about how to determine the version of the sql server using things like @@VERSION, or SERVERPROPERTY('productversion') but none of these work with sql server compact edition 4.

Is there some universally supported method to determine which sql server edition and version is in use through a sql query or code that works for compact edition all the way to full sql server?

I want to determine which exact edition / version of SQL server is in use so I know what type of paging query to issue from my code. Sql CE 4 uses a new format for paging queries same as sql server 2011 (denali) and 2005 and 2008 have their own method that is unsupported in CE 4.

I think the answer is that it's impossible but I just want to be sure I didn't overlook something.

Answer Source

I don't really work with SQL Server anymore but here is my attempt at this little problem.

For version 4 of compact edition the following should give you the version and build.

var ver = new System.Data.SqlServerCe.SqlCeConnection().ServerVersion;

And the following should give you the assembly version

var version = typeof(System.Data.SqlServerCe.SqlCeConnection).Assembly.GetName().Version;