1 //---------------------------------------------------------------------
2 // <copyright file="SqlVersion.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 namespace System.Data.SqlClient
13 using System.Data.Entity;
14 using System.Globalization;
17 /// This enum describes the current server version
19 internal enum SqlVersion
36 // higher versions go here
40 /// This class is a simple utility class that determines the sql version from the
43 internal static class SqlVersionUtils
46 /// Get the SqlVersion from the connection. Returns one of Sql8, Sql9, Sql10
47 /// The passed connection must be open
49 /// <param name="connection">current sql connection</param>
50 /// <returns>Sql Version for the current connection</returns>
51 internal static SqlVersion GetSqlVersion(SqlConnection connection)
53 System.Diagnostics.Debug.Assert(connection.State == ConnectionState.Open, "Expected an open connection");
54 int majorVersion = Int32.Parse(connection.ServerVersion.Substring(0, 2), CultureInfo.InvariantCulture);
55 if (majorVersion >= 10)
57 return SqlVersion.Sql10;
59 else if (majorVersion == 9)
61 return SqlVersion.Sql9;
65 System.Diagnostics.Debug.Assert(majorVersion == 8, "not version 8");
66 return SqlVersion.Sql8;
70 internal static string GetVersionHint(SqlVersion version)
75 return SqlProviderManifest.TokenSql8;
78 return SqlProviderManifest.TokenSql9;
80 case SqlVersion.Sql10:
81 return SqlProviderManifest.TokenSql10;
84 throw EntityUtil.Argument(Strings.UnableToDetermineStoreVersion);
88 internal static SqlVersion GetSqlVersion(string versionHint)
90 if (!string.IsNullOrEmpty(versionHint))
94 case SqlProviderManifest.TokenSql8:
95 return SqlVersion.Sql8;
97 case SqlProviderManifest.TokenSql9:
98 return SqlVersion.Sql9;
100 case SqlProviderManifest.TokenSql10:
101 return SqlVersion.Sql10;
105 throw EntityUtil.Argument(Strings.UnableToDetermineStoreVersion);
108 internal static bool IsPreKatmai(SqlVersion sqlVersion)
110 return sqlVersion == SqlVersion.Sql8 || sqlVersion == SqlVersion.Sql9;