我现在在 PowerShell 中使用 Invoke-ASCmd
在 SQL Server 中创建数据库,如下所示:
Invoke-ascmd -Query $MyScript -Server $ASServer
其中 $MyScript
是一个字符串,其中包含我之前读入的 .xmla 文件的内容。
这很好用。现在我需要在 C# 中做一些类似的事情,但我无法找到像 PowerShell 中存在的那样的简单解决方案。
我看到有些人使用名为 Microsoft.AnalysisServices.XMLA.dll
的 Microsoft DLL,但它不受支持,而且有问题的类是“内部的”,所以我什至无法引用它.
我在四处搜索时找到了这个 DLL Microsoft.AnalysisServices.AdomdClient.dll
,但没有看到任何与我需要的类相关的类:https://learn.microsoft.com/en-us/dotnet/api/microsoft.analysisservices.adomdclient?view=analysisservices-dotnet
最佳答案
using Microsoft.AnalysisServices.AdomdClient;
try
{
var xmlaFileContents = File.ReadAllText("path/to/your/file.xmla");
using (AdomdCommand cmd = conn.CreateCommand())
{
cmd.CommandText = xmlaFileContents;
cmd.ExecuteNoQuery();
}
}
catch(Exception)
{
}
** 请注意,我没有运行这段代码 **
关于c# - .xmla 使用 C# 部署到 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57190762/