mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user