fix Azure Authentication for renaming (#1946)

This commit is contained in:
Alan Ren
2023-03-15 15:55:52 -07:00
committed by GitHub
parent fbff67cd95
commit 55887b7c26

View File

@@ -6,7 +6,6 @@
#nullable disable #nullable disable
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
@@ -66,11 +65,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
requestParams.ConnectionUri, requestParams.ConnectionUri,
out connInfo)) out connInfo))
{ {
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, ObjectManagementServiceApplicationName)) ServerConnection serverConnection = ConnectionService.OpenServerConnection(connInfo, ObjectManagementServiceApplicationName);
using (serverConnection.SqlConnectionObject)
{ {
IRenamable renameObject = this.GetRenamable(requestParams, serverConnection);
IRenamable renameObject = this.GetRenamable(requestParams, sqlConn);
renameObject.Rename(requestParams.NewName); renameObject.Rename(requestParams.NewName);
} }
} }
@@ -87,12 +85,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
/// Method to get the sql object, which should be renamed /// Method to get the sql object, which should be renamed
/// </summary> /// </summary>
/// <param name="requestParams">parameters which are required for the rename operation</param> /// <param name="requestParams">parameters which are required for the rename operation</param>
/// <param name="connection">the sqlconnection on the server to search for the sqlobject</param> /// <param name="connection">the server connection on the server to search for the sqlobject</param>
/// <returns>the sql object if implements the interface IRenamable, so they can be renamed</returns> /// <returns>the sql object if implements the interface IRenamable, so they can be renamed</returns>
private IRenamable GetRenamable(RenameRequestParams requestParams, SqlConnection connection) private IRenamable GetRenamable(RenameRequestParams requestParams, ServerConnection connection)
{ {
ServerConnection serverConnection = new ServerConnection(connection); Server server = new Server(connection);
Server server = new Server(serverConnection);
SqlSmoObject dbObject = server.GetSmoObject(new Urn(requestParams.ObjectUrn)); SqlSmoObject dbObject = server.GetSmoObject(new Urn(requestParams.ObjectUrn));
return (IRenamable)dbObject; return (IRenamable)dbObject;
} }