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
This commit is contained in:
Leila Lali
2017-11-02 22:39:38 +00:00
committed by Karl Burtram
parent 54c29f20a6
commit 3bb86af10b

View File

@@ -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));
}
}