microsoft / microsoft/sqlmanagementobjects

`ClearAndInitialize()` fails when called on the Databases property of a Dynamics CRM server

Open
#207 1 comment 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
143
Forks
28
PR merge metrics
No merged PRs in 30d

Description

This was working in 171.30.0 but has been broken since 172.52.0 (including latest).

Minimal repro:

using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder("Data Source=org12345678.crm.dynamics.com,1433;User ID=sample@microsoft.com;Authentication=ActiveDirectoryInteractive");

Server server = new Server(new ServerConnection(new SqlConnection(connectionString.ConnectionString)));
var databases = server.Databases;

try
{
    databases.ClearAndInitialize("[(@IsSystemObject = 0)]", ["Status"]);
    Console.WriteLine("Databases initialized successfully.");
} catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Error message:

An exception occurred while executing a Transact-SQL statement or batch.
Inner exception: CREATE TABLE' statement​ is not supported. Line:2, Position:9

Stack trace:

   at Microsoft.SqlServer.Management.Common.ServerConnection.GetExecuteReader(SqlCommand command)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteReader(String sqlCommand, SqlCommand& command)
   at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataReader(String query, SqlCommand& command)
   at Microsoft.SqlServer.Management.Smo.DataProvider.SetConnectionAndQuery(ExecuteSql execSql, String query)
   at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataProvider(StringCollection query, Object con, StatementBuilder sb, RetriveMode rm)
   at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataProvider(StringCollection query, Object con, StatementBuilder sb)
   at Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillData(ResultType resultType, StringCollection sql, Object connectionInfo, StatementBuilder sb)
   at Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillDataWithUseFailure(SqlEnumResult sqlresult, ResultType resultType)
   at Microsoft.SqlServer.Management.Smo.SqlObjectBase.BuildResult(EnumResult result)
   at Microsoft.SqlServer.Management.Smo.DatabaseLevel.GetData(EnumResult res)
   at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData()
   at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData(Request req, Object ci)
   at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object connectionInfo, Request request)
   at Microsoft.SqlServer.Management.Smo.ExecutionManager.GetEnumeratorDataReader(Request req)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitChildLevel(Urn levelFilter, ScriptingPreferences sp, Boolean forScripting, IEnumerable`1 extraFields)
   at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.InitializeChildCollection(Boolean refresh, ScriptingPreferences sp, String filterQuery, IEnumerable`1 extraFields)
   at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.ClearAndInitialize(String filterQuery, IEnumerable`1 extraFields)
   at Program.<Main>$(String[] args)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.