microsoft / microsoft/sqlmanagementobjects

Trying to create User of External UserType against a SqlManagedInstance results in error

オープン
#112 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
C#
スター
143
フォーク
28
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi @shueybubbles, greetings from the dbatools team 😄

I'm trying to add a SqlUser of type [Microsoft.SqlServer.Management.Smo.UserType]::External on a newly created SQL MI.

DatabaseEngineEdition: SqlManagedInstance
ServerVersion.Major: 16
SMO Version: 16
File version: 16.200.46367.54

I'm getting the following exception:

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "Create" with "0" argument(s): "Create failed for 
                        User 'claudio@********.onmicrosoft.com'. "
                         ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Create failed for User
                        'claudio@********.onmicrosoft.com'.
                         ---> Microsoft.SqlServer.Management.Smo.UnsupportedVersionException: 'User'.'UserType': 'External' is not a valid option for SQL Server 2017.

Code to reproduce:

$smoUser = New-Object Microsoft.SqlServer.Management.Smo.User
$smoUser.Parent = $dbSMO
$smoUser.Name = "claudio@********.onmicrosoft.com"
$smoUser.Login = "claudio@********.onmicrosoft.com"
$smoUser.UserType = [Microsoft.SqlServer.Management.Smo.UserType]::External
$smoUser.DefaultSchema = "dbo"
$smoUser.Create()

Note: with T-SQL it works.

From my analysis the problem is here (assuming the comment): https://github.com/microsoft/sqlmanagementobjects/blob/98093604e9ede97aa2a9b066279f0bd9d9557c4f/src/Microsoft/SqlServer/Management/Smo/UserBase.cs#L362-L364

It should be 12 <= this.ServerVersion.Major instead of >

Error message

Also, the error message says SQL Server 2017 when it should say SQL Server Managed Instance
It seems it's entering here:
https://github.com/microsoft/sqlmanagementobjects/blob/04249a2dc85ad1aa0d492b8a2cecf65583ded177/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs#L6919

I would suggest adding a new validation similar with
https://github.com/microsoft/sqlmanagementobjects/blob/04249a2dc85ad1aa0d492b8a2cecf65583ded177/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs#L6898-L6901

But like:

if (sp.TargetDatabaseEngineType == DatabaseEngineType.SqlAzureDatabase)
{
    return LocalizableResources.EngineCloud;
}
else if (sp.TargetDatabaseEngineType == DatabaseEngineType.Standalone && sp.DatabaseEngineEdition == DatabaseEngineEdition.SqlManagedInstance)
{
    return LocalizableResources.EngineCloudMI;
}

And add here:
https://github.com/microsoft/sqlmanagementobjects/blob/73cd2cb929409cb9ddc2c7b416c5d7c6ef621d5f/src/Microsoft/SqlServer/Management/Smo/LocalizableResources.strings#L26
A new entry

EngineCloudMI = Microsoft Azure SQL Managed Instance

PS: I'm more than happy to submit a PR with these changes if it's ok for you.
Thanks!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、UserType の検証に関する UserBase.cs の引用された行から確認し、次に SqlSmoObject.cs と LocalizableResources.strings のエンジン名のロジックを調べます。SQL Managed Instance に対する External ユーザーの作成を再現し、検証でバージョンが受け入れられることと、結果のエラーが Azure SQL Managed Instance を正しく識別することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, sql
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。