This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
SqlVersionUtils.cs
83 lines (73 loc) · 2.88 KB
/
SqlVersionUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.SqlServer
{
using System.Data.Entity.SqlServer.Resources;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
/// <summary>
/// This class is a simple utility class that determines the sql version from the
/// connection
/// </summary>
internal static class SqlVersionUtils
{
/// <summary>
/// Get the SqlVersion from the connection. Returns one of Sql8, Sql9, Sql10
/// The passed connection must be open
/// </summary>
/// <param name="connection">current sql connection</param>
/// <returns>Sql Version for the current connection</returns>
internal static SqlVersion GetSqlVersion(SqlConnection connection)
{
Debug.Assert(connection.State == ConnectionState.Open, "Expected an open connection");
var majorVersion = Int32.Parse(connection.ServerVersion.Substring(0, 2), CultureInfo.InvariantCulture);
if (majorVersion >= 10)
{
return SqlVersion.Sql10;
}
else if (majorVersion == 9)
{
return SqlVersion.Sql9;
}
else
{
Debug.Assert(majorVersion == 8, "not version 8");
return SqlVersion.Sql8;
}
}
internal static string GetVersionHint(SqlVersion version)
{
switch (version)
{
case SqlVersion.Sql8:
return SqlProviderManifest.TokenSql8;
case SqlVersion.Sql9:
return SqlProviderManifest.TokenSql9;
case SqlVersion.Sql10:
return SqlProviderManifest.TokenSql10;
default:
throw new ArgumentException(Strings.UnableToDetermineStoreVersion);
}
}
internal static SqlVersion GetSqlVersion(string versionHint)
{
if (!string.IsNullOrEmpty(versionHint))
{
switch (versionHint)
{
case SqlProviderManifest.TokenSql8:
return SqlVersion.Sql8;
case SqlProviderManifest.TokenSql9:
return SqlVersion.Sql9;
case SqlProviderManifest.TokenSql10:
return SqlVersion.Sql10;
}
}
throw new ArgumentException(Strings.UnableToDetermineStoreVersion);
}
internal static bool IsPreKatmai(SqlVersion sqlVersion)
{
return sqlVersion == SqlVersion.Sql8 || sqlVersion == SqlVersion.Sql9;
}
}
}