mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -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.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
|
||||||
using Microsoft.SqlServer.Management.SqlScriptPublish;
|
using Microsoft.SqlServer.Management.SqlScriptPublish;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
using static Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptOptions;
|
using static Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptOptions;
|
||||||
|
using Microsoft.SqlServer.Management.Common;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||||
{
|
{
|
||||||
@@ -246,27 +246,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
|||||||
{
|
{
|
||||||
string serverName = null;
|
string serverName = null;
|
||||||
using(SqlConnection connection = new SqlConnection(connectionString))
|
using(SqlConnection connection = new SqlConnection(connectionString))
|
||||||
using (SqlCommand cmd = connection.CreateCommand())
|
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select @@servername";
|
|
||||||
serverName = (string)cmd.ExecuteScalar();
|
ServerConnection serverConnection = new ServerConnection(connection);
|
||||||
|
serverName = serverConnection.TrueName;
|
||||||
}
|
}
|
||||||
catch (SqlException e)
|
catch (SqlException e)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Azure SQL Data Warehouse does not support @@servername, so fallback to SERVERPROPERTY.
|
|
||||||
//
|
|
||||||
|
|
||||||
Logger.Write(
|
Logger.Write(
|
||||||
LogLevel.Verbose,
|
LogLevel.Verbose,
|
||||||
string.Format("Exception running query 'SELECT @@servername' {0}, fallback to SERVERPROPERTY query", e));
|
string.Format("Exception getting server name", e));
|
||||||
|
|
||||||
cmd.CommandText = "select SERVERPROPERTY('ServerName') AS ServerName";
|
|
||||||
serverName = (string)cmd.ExecuteScalar();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user