Reputation: 1856
I have an app that creates SQL tables and enables DATA_COMPRESSION=Page. However, that feature is only available when the Enterprise version of SQLServer is being used. There are times when I would like to use this same code on, for example, a SQLLocalDB SKU. For these cases I would like to skip the DATA_COMPRESSION setting because it is not supported and throws an error.
Is it possible for me to detect if this feature is available, (or next best), detect that SQLLocalDB is being used?
I'm using ADO.net to connect to the database.
Upvotes: 1
Views: 41
Reputation: 20754
You can open an SqlConnection
to database and check ServerVersion
using (var con = new SqlConnection(connectionString))
{
connection.Open();
// use con.ServerVersion
}
If you want to know more details you can query for properties by using SERVERPROPERTY
SELECT SERVERPROPERTY('Edition')
Or
SELECT SERVERPROPERTY('EngineEdition')
Database Engine edition of the instance of SQL Server installed on the server.
1 = Personal or Desktop Engine (Not available in SQL Server 2005 and later versions.)
2 = Standard (This is returned for Standard, Web, and Business Intelligence.)
3 = Enterprise (This is returned for Evaluation, Developer, and both Enterprise editions.)
4 = Express (This is returned for Express, Express with Tools and Express with Advanced Services)
5 = SQL Database
6 - SQL Data Warehouse
Base data type: int
Upvotes: 2