From 3bb86af10b6af2c47a4e337f78023a44c4cf47bf Mon Sep 17 00:00:00 2001 From: Leila Lali Date: Thu, 2 Nov 2017 22:39:38 +0000 Subject: [PATCH] Fix/scripting server name (#543) * binding queue should not throw excpetion if fails to connect * getting the server name using the server connection * removed extra comment --- .../Scripting/ScriptingScriptOperation.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingScriptOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingScriptOperation.cs index 5680e432..466f1d67 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingScriptOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingScriptOperation.cs @@ -9,11 +9,11 @@ using System.Data.SqlClient; using System.IO; using System.Linq; using System.Reflection; -using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.SqlScriptPublish; using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts; using Microsoft.SqlTools.Utility; using static Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptOptions; +using Microsoft.SqlServer.Management.Common; namespace Microsoft.SqlTools.ServiceLayer.Scripting { @@ -246,27 +246,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting { string serverName = null; using(SqlConnection connection = new SqlConnection(connectionString)) - using (SqlCommand cmd = connection.CreateCommand()) - { + { connection.Open(); try { - cmd.CommandText = "select @@servername"; - serverName = (string)cmd.ExecuteScalar(); + + ServerConnection serverConnection = new ServerConnection(connection); + serverName = serverConnection.TrueName; } catch (SqlException e) { - // - // Azure SQL Data Warehouse does not support @@servername, so fallback to SERVERPROPERTY. - // - Logger.Write( LogLevel.Verbose, - string.Format("Exception running query 'SELECT @@servername' {0}, fallback to SERVERPROPERTY query", e)); - - cmd.CommandText = "select SERVERPROPERTY('ServerName') AS ServerName"; - serverName = (string)cmd.ExecuteScalar(); + string.Format("Exception getting server name", e)); } }