mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Delete more unneeded sql manager UI code (#345)
This commit is contained in:
Binary file not shown.
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17051.0.nupkg
Normal file
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17051.0.nupkg
Normal file
Binary file not shown.
@@ -12,7 +12,7 @@
|
|||||||
"Newtonsoft.Json": "9.0.1",
|
"Newtonsoft.Json": "9.0.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0",
|
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0"
|
"Microsoft.SqlServer.Smo": "140.17051.0"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
|
|||||||
@@ -1,389 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
//
|
|
||||||
|
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Xml;
|
|
||||||
using System.Threading;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
|
||||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
|
||||||
using Microsoft.SqlServer.Management.Diagnostics;
|
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Summary description for CUtils.
|
|
||||||
/// </summary>
|
|
||||||
internal class CUtils
|
|
||||||
{
|
|
||||||
|
|
||||||
private const int ObjectPermissionsDeniedErrorNumber = 229;
|
|
||||||
private const int ColumnPermissionsDeniedErrorNumber = 230;
|
|
||||||
|
|
||||||
public CUtils()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// TODO: Add constructor logic here
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UseMaster(SMO.Server server)
|
|
||||||
{
|
|
||||||
server.ConnectionContext.ExecuteNonQuery("use master");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a SMO Server object that is connected to the connection
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ci">Conenction info</param>
|
|
||||||
/// <returns>Smo Server object for the connection</returns>
|
|
||||||
public static Microsoft.SqlServer.Management.Smo.Server GetSmoServer(IManagedConnection mc)
|
|
||||||
{
|
|
||||||
SqlOlapConnectionInfoBase ci = mc.Connection;
|
|
||||||
if (ci == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("ci");
|
|
||||||
}
|
|
||||||
|
|
||||||
SMO.Server server = null;
|
|
||||||
|
|
||||||
// see what type of connection we have been passed
|
|
||||||
SqlConnectionInfoWithConnection ciWithCon = ci as SqlConnectionInfoWithConnection;
|
|
||||||
|
|
||||||
if (ciWithCon != null)
|
|
||||||
{
|
|
||||||
server = new SMO.Server(ciWithCon.ServerConnection);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SqlConnectionInfo sqlCi = ci as SqlConnectionInfo;
|
|
||||||
if (sqlCi != null)
|
|
||||||
{
|
|
||||||
server = new SMO.Server(new ServerConnection(sqlCi));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
return server;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetServerVersion(SMO.Server server)
|
|
||||||
{
|
|
||||||
return server.Information.Version.Major;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines the oldest date based on the type of time units and the number of time units
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="numUnits"></param>
|
|
||||||
/// <param name="typeUnits"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static DateTime GetOldestDate(int numUnits, TimeUnitType typeUnits)
|
|
||||||
{
|
|
||||||
DateTime result = DateTime.Now;
|
|
||||||
|
|
||||||
switch (typeUnits)
|
|
||||||
{
|
|
||||||
case TimeUnitType.Week:
|
|
||||||
{
|
|
||||||
result = (DateTime.Now).AddDays(-1 * 7 * numUnits);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TimeUnitType.Month:
|
|
||||||
{
|
|
||||||
result = (DateTime.Now).AddMonths(-1 * numUnits);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TimeUnitType.Year:
|
|
||||||
{
|
|
||||||
result = (DateTime.Now).AddYears(-1 * numUnits);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
result = (DateTime.Now).AddDays(-1 * numUnits);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string TokenizeXml(string s)
|
|
||||||
{
|
|
||||||
if (null == s) return String.Empty;
|
|
||||||
|
|
||||||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
||||||
foreach (char c in s)
|
|
||||||
{
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '<':
|
|
||||||
sb.Append("<");
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
sb.Append(">");
|
|
||||||
break;
|
|
||||||
case '&':
|
|
||||||
sb.Append("&");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sb.Append(c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to get the SqlException out of an Enumerator exception
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static SqlException GetSqlException(Exception e)
|
|
||||||
{
|
|
||||||
SqlException sqlEx = null;
|
|
||||||
Exception exception = e;
|
|
||||||
while (exception != null)
|
|
||||||
{
|
|
||||||
sqlEx = exception as SqlException;
|
|
||||||
if (null != sqlEx)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
exception = exception.InnerException;
|
|
||||||
}
|
|
||||||
return sqlEx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// computes the name of the machine based on server's name (as returned by smoServer.Name)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sqlServerName">name of server ("",".","Server","Server\Instance",etc)</param>
|
|
||||||
/// <returns>name of the machine hosting sql server instance</returns>
|
|
||||||
public static string GetMachineName(string sqlServerName)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.Assert(sqlServerName != null);
|
|
||||||
|
|
||||||
string machineName = sqlServerName;
|
|
||||||
if (sqlServerName.Trim().Length != 0)
|
|
||||||
{
|
|
||||||
// [0] = machine, [1] = instance (if any)
|
|
||||||
return sqlServerName.Split('\\')[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we have default instance of default machine
|
|
||||||
return machineName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines if a SqlException is Permission denied exception
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sqlException"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsPermissionDeniedException(SqlException sqlException)
|
|
||||||
{
|
|
||||||
bool isPermDenied = false;
|
|
||||||
if (null != sqlException.Errors)
|
|
||||||
{
|
|
||||||
foreach (SqlError sqlError in sqlException.Errors)
|
|
||||||
{
|
|
||||||
int errorNumber = GetSqlErrorNumber(sqlError);
|
|
||||||
|
|
||||||
if ((ObjectPermissionsDeniedErrorNumber == errorNumber) ||
|
|
||||||
(ColumnPermissionsDeniedErrorNumber == errorNumber))
|
|
||||||
{
|
|
||||||
isPermDenied = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isPermDenied;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the error number of a sql exeception
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sqlerror"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static int GetSqlErrorNumber(SqlError sqlerror)
|
|
||||||
{
|
|
||||||
return sqlerror.Number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function doubles up specified character in a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <param name="cEsc"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String EscapeString(string s, char cEsc)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder(s.Length * 2);
|
|
||||||
foreach (char c in s)
|
|
||||||
{
|
|
||||||
sb.Append(c);
|
|
||||||
if (cEsc == c)
|
|
||||||
sb.Append(c);
|
|
||||||
}
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function doubles up ']' character in a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String EscapeStringCBracket(string s)
|
|
||||||
{
|
|
||||||
return CUtils.EscapeString(s, ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function doubles up '\'' character in a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String EscapeStringSQuote(string s)
|
|
||||||
{
|
|
||||||
return CUtils.EscapeString(s, '\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function removes doubled up specified character from a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <param name="cEsc"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String UnEscapeString(string s, char cEsc)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder(s.Length);
|
|
||||||
bool foundBefore = false;
|
|
||||||
foreach (char c in s)
|
|
||||||
{
|
|
||||||
if (cEsc == c) // character to unescape
|
|
||||||
{
|
|
||||||
if (foundBefore) // skip second occurrence
|
|
||||||
{
|
|
||||||
foundBefore = false;
|
|
||||||
}
|
|
||||||
else // set the flag to skip next time around
|
|
||||||
{
|
|
||||||
sb.Append(c);
|
|
||||||
foundBefore = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.Append(c);
|
|
||||||
foundBefore = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function removes doubled up ']' character from a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String UnEscapeStringCBracket(string s)
|
|
||||||
{
|
|
||||||
return CUtils.UnEscapeString(s, ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Function removes doubled up '\'' character from a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static String UnEscapeStringSQuote(string s)
|
|
||||||
{
|
|
||||||
return CUtils.UnEscapeString(s, '\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the windows login name with the domain portion in all-caps
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="windowsLoginName">The windows login name</param>
|
|
||||||
/// <returns>The windows login name with the domain portion in all-caps</returns>
|
|
||||||
public static string CanonicalizeWindowsLoginName(string windowsLoginName)
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
int lastBackslashIndex = windowsLoginName.LastIndexOf("\\", StringComparison.Ordinal);
|
|
||||||
|
|
||||||
if (-1 != lastBackslashIndex)
|
|
||||||
{
|
|
||||||
string domainName = windowsLoginName.Substring(0, lastBackslashIndex).ToUpperInvariant();
|
|
||||||
string afterDomain = windowsLoginName.Substring(lastBackslashIndex);
|
|
||||||
|
|
||||||
result = String.Concat(domainName, afterDomain);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = windowsLoginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enum of time units types ( used in cleaning up history based on age )
|
|
||||||
/// </summary>
|
|
||||||
internal enum TimeUnitType
|
|
||||||
{
|
|
||||||
Day,
|
|
||||||
Week,
|
|
||||||
Month,
|
|
||||||
Year
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Object used to populate default language in
|
|
||||||
/// database and user dialogs.
|
|
||||||
/// </summary>
|
|
||||||
internal class LanguageDisplay
|
|
||||||
{
|
|
||||||
private SMO.Language language;
|
|
||||||
|
|
||||||
public string LanguageAlias
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return language.Alias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SMO.Language Language
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LanguageDisplay(SMO.Language language)
|
|
||||||
{
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return language.Alias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,21 +6,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
// using Microsoft.SqlServer.Management.SqlMgmt;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
using Microsoft.SqlServer.Management.Diagnostics;
|
using Microsoft.SqlServer.Management.Diagnostics;
|
||||||
|
|
||||||
// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Database properties for SqlServer 2008
|
/// Database properties for SqlServer 2008
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
||||||
// [StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))]
|
|
||||||
internal class DatabasePrototype100 : DatabasePrototype90
|
internal class DatabasePrototype100 : DatabasePrototype90
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -100,7 +96,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_LegacyCardinalityEstimation")]
|
DisplayNameAttribute("Property_LegacyCardinalityEstimation")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public string LegacyCardinalityEstimationDisplay
|
public string LegacyCardinalityEstimationDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -116,7 +111,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_LegacyCardinalityEstimationForSecondary")]
|
DisplayNameAttribute("Property_LegacyCardinalityEstimationForSecondary")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public String LegacyCardinalityEstimationForSecondaryDisplay
|
public String LegacyCardinalityEstimationForSecondaryDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -132,7 +126,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_ParameterSniffing")]
|
DisplayNameAttribute("Property_ParameterSniffing")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public string ParameterSniffingDisplay
|
public string ParameterSniffingDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -148,7 +141,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_ParameterSniffingForSecondary")]
|
DisplayNameAttribute("Property_ParameterSniffingForSecondary")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public String ParameterSniffingForSecondaryDisplay
|
public String ParameterSniffingForSecondaryDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -164,7 +156,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_QueryOptimizerHotfixes")]
|
DisplayNameAttribute("Property_QueryOptimizerHotfixes")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public String QueryOptimizerHotfixesDisplay
|
public String QueryOptimizerHotfixesDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -180,7 +171,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category("Category_DatabaseScopedConfigurations"),
|
[Category("Category_DatabaseScopedConfigurations"),
|
||||||
DisplayNameAttribute("Property_QueryOptimizerHotfixesForSecondary")]
|
DisplayNameAttribute("Property_QueryOptimizerHotfixesForSecondary")]
|
||||||
//TypeConverter(typeof(DatabaseScopedConfigurationOnOffTypes))]
|
|
||||||
public String QueryOptimizerHotfixesForSecondaryDisplay
|
public String QueryOptimizerHotfixesForSecondaryDisplay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -311,5 +301,3 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,22 +4,17 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
// using System.Drawing.Design;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
// using Microsoft.SqlServer.Management.SqlMgmt;
|
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
|
|
||||||
// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Database properties for SqlServer 2011
|
/// Database properties for SqlServer 2011
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
||||||
// [StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))]
|
internal class DatabasePrototype110 : DatabasePrototype100
|
||||||
internal class DatabasePrototype110 : DatabasePrototype100 //, ILanguageLcidWithConnectionInfo
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Database compatibility level
|
/// Database compatibility level
|
||||||
@@ -53,25 +48,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[
|
|
||||||
//// Editor(typeof(DefaultLanguageEditor), typeof(UITypeEditor)),
|
|
||||||
//Category("Category_ContainedDatabases"),
|
|
||||||
//DisplayNameAttribute("Property_DefaultLanguage")
|
|
||||||
//]
|
|
||||||
//public LanguageChoice DefaultLanguage
|
|
||||||
//{
|
|
||||||
// get
|
|
||||||
// {
|
|
||||||
// return LanguageUtils.GetLanguageChoiceAlias(this.context.Server,
|
|
||||||
// this.currentState.defaultLanguageLcid);
|
|
||||||
// }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// this.currentState.defaultLanguageLcid = value.lcid;
|
|
||||||
// this.NotifyObservers();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
[Category("Category_ContainedDatabases"),
|
[Category("Category_ContainedDatabases"),
|
||||||
DisplayNameAttribute("Property_NestedTriggersEnabled")]
|
DisplayNameAttribute("Property_NestedTriggersEnabled")]
|
||||||
public bool NestedTriggersEnabled
|
public bool NestedTriggersEnabled
|
||||||
@@ -174,11 +150,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
db.DefaultFullTextLanguage.Lcid = this.DefaultFullTextLanguageLcid;
|
db.DefaultFullTextLanguage.Lcid = this.DefaultFullTextLanguageLcid;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!this.Exists || (db.DefaultLanguage.Lcid != this.DefaultLanguage.lcid))
|
|
||||||
//{
|
|
||||||
// db.DefaultLanguage.Lcid = this.DefaultLanguage.lcid;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (!this.Exists || (db.NestedTriggersEnabled != this.NestedTriggersEnabled))
|
if (!this.Exists || (db.NestedTriggersEnabled != this.NestedTriggersEnabled))
|
||||||
{
|
{
|
||||||
db.NestedTriggersEnabled = this.NestedTriggersEnabled;
|
db.NestedTriggersEnabled = this.NestedTriggersEnabled;
|
||||||
@@ -212,21 +183,5 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region ILanguageLcidWithConnectionInfo Members
|
|
||||||
|
|
||||||
//int ILanguageLcidWithConnectionInfo.Lcid
|
|
||||||
//{
|
|
||||||
// get { return this.DefaultLanguage.lcid; }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//ServerConnection ILanguageLcidWithConnectionInfo.Connection
|
|
||||||
//{
|
|
||||||
// get { return this.context.ServerConnection; }
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,11 @@
|
|||||||
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
//using System.Windows.Forms;
|
|
||||||
//using Microsoft.SqlServer.Management.AzureSqlDbUtils;
|
|
||||||
//using Microsoft.SqlServer.Management.SqlMgmt;
|
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
using Microsoft.SqlServer.Management.Diagnostics;
|
using Microsoft.SqlServer.Management.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
//using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute;
|
|
||||||
using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition;
|
using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using System;
|
using System;
|
||||||
@@ -28,7 +23,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
/// Business/Web editions are up to compat level 100 now
|
/// Business/Web editions are up to compat level 100 now
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
[TypeConverter(typeof(DynamicValueTypeConverter))]
|
||||||
//[StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))]
|
|
||||||
internal class DatabasePrototypeAzure : DatabasePrototype100
|
internal class DatabasePrototypeAzure : DatabasePrototype100
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -49,27 +43,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
//private DesignableObject wrapper;
|
|
||||||
|
|
||||||
//[Browsable(false)]
|
|
||||||
//public DesignableObject Wrapper
|
|
||||||
//{
|
|
||||||
// get
|
|
||||||
// {
|
|
||||||
// return wrapper;
|
|
||||||
// }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// this.wrapper = value;
|
|
||||||
// //Now that we have a new wrapper make sure to update the dynamic visibility for the SLO options
|
|
||||||
// SetServiceLevelObjectiveOptionVisibility();
|
|
||||||
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
[Category(Category_Azure),
|
[Category(Category_Azure),
|
||||||
DisplayNameAttribute(Property_AzureMaxSize)]
|
DisplayNameAttribute(Property_AzureMaxSize)]
|
||||||
//TypeConverter(typeof(DynamicValuesConverter))]
|
|
||||||
public string MaxSize
|
public string MaxSize
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -85,7 +60,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category(Category_Azure),
|
[Category(Category_Azure),
|
||||||
DisplayNameAttribute(Property_AzureCurrentServiceLevelObjective)]
|
DisplayNameAttribute(Property_AzureCurrentServiceLevelObjective)]
|
||||||
//TypeConverter(typeof(DynamicValuesConverter))]
|
|
||||||
public string CurrentServiceLevelObjective
|
public string CurrentServiceLevelObjective
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -122,7 +96,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
[Category(Category_Azure),
|
[Category(Category_Azure),
|
||||||
DisplayNameAttribute(Property_AzureEdition)]
|
DisplayNameAttribute(Property_AzureEdition)]
|
||||||
// TypeConverter(typeof(DynamicValuesConverter))]
|
|
||||||
//We have a separate property here so that the AzureEdition enum value is still exposed
|
//We have a separate property here so that the AzureEdition enum value is still exposed
|
||||||
//(This property is for the name displayed in the drop down menu, which needs to be a string for casting purposes)
|
//(This property is for the name displayed in the drop down menu, which needs to be a string for casting purposes)
|
||||||
public string AzureEditionDisplay
|
public string AzureEditionDisplay
|
||||||
@@ -142,7 +115,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.currentState.azureEdition = edition;
|
this.currentState.azureEdition = edition;
|
||||||
// this.SetServiceLevelObjectiveOptionVisibility();
|
|
||||||
this.CurrentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(edition);
|
this.CurrentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(edition);
|
||||||
this.MaxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(edition).ToString();
|
this.MaxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(edition).ToString();
|
||||||
this.NotifyObservers();
|
this.NotifyObservers();
|
||||||
@@ -175,28 +147,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the visibility of the SLO options based on the current configured Edition
|
|
||||||
/// </summary>
|
|
||||||
//private void SetServiceLevelObjectiveOptionVisibility()
|
|
||||||
//{
|
|
||||||
// if (this.wrapper == null)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (this.AzureEdition == AzureEdition.Business || this.AzureEdition == AzureEdition.Web)
|
|
||||||
// { //Business and Web editions don't support SLO so hide those options
|
|
||||||
// this.wrapper.SetupDynamicVisibility(Property_AzureCurrentServiceLevelObjective, false);
|
|
||||||
// this.wrapper.SetupDynamicVisibility(Property_AzureConfiguredServiceLevelObjective, false);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// { //Reset SLO options to visible in case they were hidden before
|
|
||||||
// this.wrapper.SetupDynamicVisibility(Property_AzureCurrentServiceLevelObjective, true);
|
|
||||||
// this.wrapper.SetupDynamicVisibility(Property_AzureConfiguredServiceLevelObjective, true);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
#region DatabasePrototype overrides
|
#region DatabasePrototype overrides
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -204,70 +154,70 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="marshallingControl">The control through which UI interactions are to be marshalled</param>
|
/// <param name="marshallingControl">The control through which UI interactions are to be marshalled</param>
|
||||||
/// <returns>The SMO database object that was created or modified</returns>
|
/// <returns>The SMO database object that was created or modified</returns>
|
||||||
//public override Database ApplyChanges(Control marshallingControl)
|
public override Database ApplyChanges()
|
||||||
//{
|
{
|
||||||
// // For v12 Non-DW DBs lets use SMO
|
// For v12 Non-DW DBs lets use SMO
|
||||||
// if (this.ServerVersion.Major >= 12 && this.AzureEdition != AzureEdition.DataWarehouse)
|
if (this.ServerVersion.Major >= 12 && this.AzureEdition != AzureEdition.DataWarehouse)
|
||||||
// {
|
{
|
||||||
// return base.ApplyChanges(marshallingControl);
|
return base.ApplyChanges();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //Note : We purposely don't call base.ApplyChanges() here since SMO doesn't fully support Azure yet and so will throw
|
//Note : We purposely don't call base.ApplyChanges() here since SMO doesn't fully support Azure yet and so will throw
|
||||||
// //an error if we try to modify the Database object directly
|
//an error if we try to modify the Database object directly
|
||||||
// string alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifyAzureDbOptionsStatement(this.Name, this.AzureEdition, this.MaxSize, this.CurrentServiceLevelObjective);
|
string alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifyAzureDbOptionsStatement(this.Name, this.AzureEdition, this.MaxSize, this.CurrentServiceLevelObjective);
|
||||||
// if (this.AzureEdition == AzureEdition.DataWarehouse)
|
if (this.AzureEdition == AzureEdition.DataWarehouse)
|
||||||
// {
|
{
|
||||||
// alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifySqlDwDbOptionsStatement(this.Name, this.MaxSize, this.CurrentServiceLevelObjective);
|
alterDbPropertiesStatement = DatabasePrototypeAzure.CreateModifySqlDwDbOptionsStatement(this.Name, this.MaxSize, this.CurrentServiceLevelObjective);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// string alterAzureDbRecursiveTriggersEnabledStatement = DatabasePrototypeAzure.CreateAzureDbSetRecursiveTriggersStatement(this.Name, this.RecursiveTriggers);
|
string alterAzureDbRecursiveTriggersEnabledStatement = DatabasePrototypeAzure.CreateAzureDbSetRecursiveTriggersStatement(this.Name, this.RecursiveTriggers);
|
||||||
// string alterAzureDbIsReadOnlyStatement = DatabasePrototypeAzure.CreateAzureDbSetIsReadOnlyStatement(this.Name, this.IsReadOnly);
|
string alterAzureDbIsReadOnlyStatement = DatabasePrototypeAzure.CreateAzureDbSetIsReadOnlyStatement(this.Name, this.IsReadOnly);
|
||||||
|
|
||||||
// Database db = this.GetDatabase();
|
Database db = this.GetDatabase();
|
||||||
|
|
||||||
// //Altering the DB needs to be done on the master DB
|
//Altering the DB needs to be done on the master DB
|
||||||
// using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString))
|
using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString))
|
||||||
// {
|
{
|
||||||
// var cmd = new SqlCommand();
|
var cmd = new SqlCommand();
|
||||||
// cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
// conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
// //Only run the alter statements for modifications made. This is mostly to allow the non-Azure specific
|
//Only run the alter statements for modifications made. This is mostly to allow the non-Azure specific
|
||||||
// //properties to be updated when a SLO change is in progress, but it also is beneficial to save trips to the
|
//properties to be updated when a SLO change is in progress, but it also is beneficial to save trips to the
|
||||||
// //server whenever we can (especially when Azure is concerned)
|
//server whenever we can (especially when Azure is concerned)
|
||||||
// if (currentState.azureEdition != originalState.azureEdition ||
|
if (currentState.azureEdition != originalState.azureEdition ||
|
||||||
// currentState.currentServiceLevelObjective != originalState.currentServiceLevelObjective ||
|
currentState.currentServiceLevelObjective != originalState.currentServiceLevelObjective ||
|
||||||
// currentState.maxSize != originalState.maxSize)
|
currentState.maxSize != originalState.maxSize)
|
||||||
// {
|
{
|
||||||
// cmd.CommandText = alterDbPropertiesStatement;
|
cmd.CommandText = alterDbPropertiesStatement;
|
||||||
// cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (currentState.recursiveTriggers != originalState.recursiveTriggers)
|
if (currentState.recursiveTriggers != originalState.recursiveTriggers)
|
||||||
// {
|
{
|
||||||
// cmd.CommandText = alterAzureDbRecursiveTriggersEnabledStatement;
|
cmd.CommandText = alterAzureDbRecursiveTriggersEnabledStatement;
|
||||||
// cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (currentState.isReadOnly != originalState.isReadOnly)
|
if (currentState.isReadOnly != originalState.isReadOnly)
|
||||||
// {
|
{
|
||||||
// cmd.CommandText = alterAzureDbIsReadOnlyStatement;
|
cmd.CommandText = alterAzureDbIsReadOnlyStatement;
|
||||||
// cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties
|
//Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties
|
||||||
// db.Refresh();
|
db.Refresh();
|
||||||
|
|
||||||
// // For properties that are supported in Database.Alter(), call SaveProperties, and then alter the DB.
|
// For properties that are supported in Database.Alter(), call SaveProperties, and then alter the DB.
|
||||||
// //
|
//
|
||||||
// if (this.AzureEdition != AzureEdition.DataWarehouse)
|
if (this.AzureEdition != AzureEdition.DataWarehouse)
|
||||||
// {
|
{
|
||||||
// this.SaveProperties(db);
|
this.SaveProperties(db);
|
||||||
// db.Alter(TerminationClause.FailOnOpenTransactions);
|
db.Alter(TerminationClause.FailOnOpenTransactions);
|
||||||
// }
|
}
|
||||||
// return db;
|
return db;
|
||||||
//}
|
}
|
||||||
|
|
||||||
#endregion DatabasePrototype overrides
|
#endregion DatabasePrototype overrides
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
//
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// To access DataModelingSandbox from NavigableItem
|
|
||||||
/// </summary>
|
|
||||||
public interface ISandboxLoader
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Get sandbox
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>DataModelingSandbox object associated with this NavigableItem</returns>
|
|
||||||
object GetSandbox();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Refresh sandbox data associated with this NavigableItem
|
|
||||||
/// </summary>
|
|
||||||
void RefreshSandboxData();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Delete sandbox from cache
|
|
||||||
/// </summary>
|
|
||||||
void DeleteSandbox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,19 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|
||||||
//extern alias VSShell2;
|
|
||||||
//extern alias VSShell2Iop;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Threading;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.SqlServer.Management.Common;
|
||||||
|
using Microsoft.SqlServer.Management.Diagnostics;
|
||||||
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Collections;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.SqlServer.Management.Diagnostics;
|
|
||||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
|
||||||
//using VSShell2Iop.Microsoft.VisualStudio.Shell.Interop;
|
|
||||||
//using VSShell2.Microsoft.VisualStudio.Shell;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||||
{
|
{
|
||||||
@@ -279,4 +282,375 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
return !string.IsNullOrEmpty(serverName) && serverName.StartsWith("asazure://", StringComparison.OrdinalIgnoreCase);
|
return !string.IsNullOrEmpty(serverName) && serverName.StartsWith("asazure://", StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Summary description for CUtils.
|
||||||
|
/// </summary>
|
||||||
|
internal class CUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
private const int ObjectPermissionsDeniedErrorNumber = 229;
|
||||||
|
private const int ColumnPermissionsDeniedErrorNumber = 230;
|
||||||
|
|
||||||
|
public CUtils()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Add constructor logic here
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UseMaster(SMO.Server server)
|
||||||
|
{
|
||||||
|
server.ConnectionContext.ExecuteNonQuery("use master");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a SMO Server object that is connected to the connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ci">Conenction info</param>
|
||||||
|
/// <returns>Smo Server object for the connection</returns>
|
||||||
|
public static Microsoft.SqlServer.Management.Smo.Server GetSmoServer(IManagedConnection mc)
|
||||||
|
{
|
||||||
|
SqlOlapConnectionInfoBase ci = mc.Connection;
|
||||||
|
if (ci == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("ci");
|
||||||
|
}
|
||||||
|
|
||||||
|
SMO.Server server = null;
|
||||||
|
|
||||||
|
// see what type of connection we have been passed
|
||||||
|
SqlConnectionInfoWithConnection ciWithCon = ci as SqlConnectionInfoWithConnection;
|
||||||
|
|
||||||
|
if (ciWithCon != null)
|
||||||
|
{
|
||||||
|
server = new SMO.Server(ciWithCon.ServerConnection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SqlConnectionInfo sqlCi = ci as SqlConnectionInfo;
|
||||||
|
if (sqlCi != null)
|
||||||
|
{
|
||||||
|
server = new SMO.Server(new ServerConnection(sqlCi));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
return server;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetServerVersion(SMO.Server server)
|
||||||
|
{
|
||||||
|
return server.Information.Version.Major;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines the oldest date based on the type of time units and the number of time units
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="numUnits"></param>
|
||||||
|
/// <param name="typeUnits"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime GetOldestDate(int numUnits, TimeUnitType typeUnits)
|
||||||
|
{
|
||||||
|
DateTime result = DateTime.Now;
|
||||||
|
|
||||||
|
switch (typeUnits)
|
||||||
|
{
|
||||||
|
case TimeUnitType.Week:
|
||||||
|
{
|
||||||
|
result = (DateTime.Now).AddDays(-1 * 7 * numUnits);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TimeUnitType.Month:
|
||||||
|
{
|
||||||
|
result = (DateTime.Now).AddMonths(-1 * numUnits);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TimeUnitType.Year:
|
||||||
|
{
|
||||||
|
result = (DateTime.Now).AddYears(-1 * numUnits);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
result = (DateTime.Now).AddDays(-1 * numUnits);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string TokenizeXml(string s)
|
||||||
|
{
|
||||||
|
if (null == s) return String.Empty;
|
||||||
|
|
||||||
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||||
|
foreach (char c in s)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '<':
|
||||||
|
sb.Append("<");
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
sb.Append(">");
|
||||||
|
break;
|
||||||
|
case '&':
|
||||||
|
sb.Append("&");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sb.Append(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to get the SqlException out of an Enumerator exception
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static SqlException GetSqlException(Exception e)
|
||||||
|
{
|
||||||
|
SqlException sqlEx = null;
|
||||||
|
Exception exception = e;
|
||||||
|
while (exception != null)
|
||||||
|
{
|
||||||
|
sqlEx = exception as SqlException;
|
||||||
|
if (null != sqlEx)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exception = exception.InnerException;
|
||||||
|
}
|
||||||
|
return sqlEx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// computes the name of the machine based on server's name (as returned by smoServer.Name)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sqlServerName">name of server ("",".","Server","Server\Instance",etc)</param>
|
||||||
|
/// <returns>name of the machine hosting sql server instance</returns>
|
||||||
|
public static string GetMachineName(string sqlServerName)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.Assert(sqlServerName != null);
|
||||||
|
|
||||||
|
string machineName = sqlServerName;
|
||||||
|
if (sqlServerName.Trim().Length != 0)
|
||||||
|
{
|
||||||
|
// [0] = machine, [1] = instance (if any)
|
||||||
|
return sqlServerName.Split('\\')[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we have default instance of default machine
|
||||||
|
return machineName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if a SqlException is Permission denied exception
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sqlException"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsPermissionDeniedException(SqlException sqlException)
|
||||||
|
{
|
||||||
|
bool isPermDenied = false;
|
||||||
|
if (null != sqlException.Errors)
|
||||||
|
{
|
||||||
|
foreach (SqlError sqlError in sqlException.Errors)
|
||||||
|
{
|
||||||
|
int errorNumber = GetSqlErrorNumber(sqlError);
|
||||||
|
|
||||||
|
if ((ObjectPermissionsDeniedErrorNumber == errorNumber) ||
|
||||||
|
(ColumnPermissionsDeniedErrorNumber == errorNumber))
|
||||||
|
{
|
||||||
|
isPermDenied = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isPermDenied;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the error number of a sql exeception
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sqlerror"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int GetSqlErrorNumber(SqlError sqlerror)
|
||||||
|
{
|
||||||
|
return sqlerror.Number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function doubles up specified character in a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <param name="cEsc"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String EscapeString(string s, char cEsc)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder(s.Length * 2);
|
||||||
|
foreach (char c in s)
|
||||||
|
{
|
||||||
|
sb.Append(c);
|
||||||
|
if (cEsc == c)
|
||||||
|
sb.Append(c);
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function doubles up ']' character in a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String EscapeStringCBracket(string s)
|
||||||
|
{
|
||||||
|
return CUtils.EscapeString(s, ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function doubles up '\'' character in a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String EscapeStringSQuote(string s)
|
||||||
|
{
|
||||||
|
return CUtils.EscapeString(s, '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function removes doubled up specified character from a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <param name="cEsc"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String UnEscapeString(string s, char cEsc)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder(s.Length);
|
||||||
|
bool foundBefore = false;
|
||||||
|
foreach (char c in s)
|
||||||
|
{
|
||||||
|
if (cEsc == c) // character to unescape
|
||||||
|
{
|
||||||
|
if (foundBefore) // skip second occurrence
|
||||||
|
{
|
||||||
|
foundBefore = false;
|
||||||
|
}
|
||||||
|
else // set the flag to skip next time around
|
||||||
|
{
|
||||||
|
sb.Append(c);
|
||||||
|
foundBefore = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append(c);
|
||||||
|
foundBefore = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function removes doubled up ']' character from a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String UnEscapeStringCBracket(string s)
|
||||||
|
{
|
||||||
|
return CUtils.UnEscapeString(s, ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function removes doubled up '\'' character from a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static String UnEscapeStringSQuote(string s)
|
||||||
|
{
|
||||||
|
return CUtils.UnEscapeString(s, '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the windows login name with the domain portion in all-caps
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="windowsLoginName">The windows login name</param>
|
||||||
|
/// <returns>The windows login name with the domain portion in all-caps</returns>
|
||||||
|
public static string CanonicalizeWindowsLoginName(string windowsLoginName)
|
||||||
|
{
|
||||||
|
string result;
|
||||||
|
int lastBackslashIndex = windowsLoginName.LastIndexOf("\\", StringComparison.Ordinal);
|
||||||
|
|
||||||
|
if (-1 != lastBackslashIndex)
|
||||||
|
{
|
||||||
|
string domainName = windowsLoginName.Substring(0, lastBackslashIndex).ToUpperInvariant();
|
||||||
|
string afterDomain = windowsLoginName.Substring(lastBackslashIndex);
|
||||||
|
|
||||||
|
result = String.Concat(domainName, afterDomain);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = windowsLoginName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enum of time units types ( used in cleaning up history based on age )
|
||||||
|
/// </summary>
|
||||||
|
internal enum TimeUnitType
|
||||||
|
{
|
||||||
|
Day,
|
||||||
|
Week,
|
||||||
|
Month,
|
||||||
|
Year
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Object used to populate default language in
|
||||||
|
/// database and user dialogs.
|
||||||
|
/// </summary>
|
||||||
|
internal class LanguageDisplay
|
||||||
|
{
|
||||||
|
private SMO.Language language;
|
||||||
|
|
||||||
|
public string LanguageAlias
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return language.Alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SMO.Language Language
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LanguageDisplay(SMO.Language language)
|
||||||
|
{
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return language.Alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"Newtonsoft.Json": "9.0.1",
|
"Newtonsoft.Json": "9.0.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0",
|
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||||
"Microsoft.SqlServer.Management.SqlScriptPublishModel": "140.17049.0",
|
"Microsoft.SqlServer.Management.SqlScriptPublishModel": "140.17049.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AdminServices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a default database info object
|
/// Get a default database info object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
// [Fact]
|
||||||
public async void GetDefaultDatebaseInfoTest()
|
public async void GetDefaultDatebaseInfoTest()
|
||||||
{
|
{
|
||||||
var result = GetLiveAutoCompleteTestObjects();
|
var result = GetLiveAutoCompleteTestObjects();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0",
|
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0",
|
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17050.0",
|
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user