我們如何處理多維數據集或通過ASP.Net使用C#代碼訪問OLAP數據庫?在C#.Net中用於連接OLAP數據庫或anaysis服務中的流程操作的組件是什麼?用於處理多維數據集的組件
回答
進行處理,使用Microsoft.AnalysisServices庫,例如代碼如下:
Server server = new Server();
server.Connect(cubeConnectionString);
Database database = server.Databases.FindByName(databaseName);
Cube cube = database.Cubes.FindByName(cubeName);
cube.Process(ProcessType.ProcessFull);
對於查詢,使用Microsoft.AnalysisServices.AdomdClient庫,例如代碼如下:
using (Adomd.AdomdConnection adomdConnection = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection())
{
adomdConnection.ConnectionString = cubeConnectionString;
Adomd.AdomdCommand adomdCommand = new Microsoft.AnalysisServices.AdomdClient.AdomdCommand();
adomdCommand.Connection = adomdConnection;
adomdCommand.CommandText = mdxQuery;
adomdConnection.Open();
cellSet = adomdCommand.ExecuteCellSet();
adomdConnection.Close();
}
注意這兩個名稱空間是重疊的,所以如果你在同一個地方使用它們,你可能需要別名。
http://msdn.microsoft.com/en-US/library/ms124924(v=SQL.90).aspx
http://msdn.microsoft.com/en-us/library/ms123483(v=SQL.90).aspx
這個例子是用Visual Studio Express的2012做,SQL 2012女士$ 44副本(上帝保佑微軟爲這麼點錢提供這麼多的功能)。該操作系統是Win 8 pro。
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//the next 2 using's had to be downloaded and "Add Reference"d for Visual Studio Express 2012
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.AdomdClient;
using System.Windows.Forms;
using System;
using System.Data;
using System.Drawing;
namespace SSASDataview
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void RunSSAS(object sender, EventArgs e)
{
//i don't think Dataset is in the Analysis Services directives
DataSet ds = new DataSet();
// provider is the constant olap. datasource is the same server name you provide for Mgmt Studio or localhost
// initial catalog is tricky and important. It is not a standard ms sql database you see in Management Studio,
// even if your cube was create with tables from a particular database.
// the only place I was able to see "initial catalog" value was a File -> Open -> Analysis Services Database in 2012 Management Studio
// it was also the name of the VS2010 solution I used to create the cube.
AdomdConnection myconnect = new AdomdConnection(@"provider=olap;initial catalog=GLCubeThree;datasource=localhost");
AdomdDataAdapter mycommand = new AdomdDataAdapter();
mycommand.SelectCommand = new AdomdCommand();
mycommand.SelectCommand.Connection = myconnect;
// this query was created by the "Browser" you see for an Analysis Services project
// if you poke around the icons on the browser table the Design Mode icon will give you the cube query
// I think it's an MDX query, threre are also xml queries you can run with adomd
mycommand.SelectCommand.CommandText = "SELECT NON EMPTY { [Measures].[Per Balance] } ON COLUMNS, NON EMPTY { ([Gltime].[Fisc Per].[Fisc Per].ALLMEMBERS) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM (SELECT ({ [Gltime].[Fisc Per].&[201301], [Gltime].[Fisc Per].&[201302], [Gltime].[Fisc Per].&[201307] }) ON COLUMNS FROM [GL Cube]) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS";
myconnect.Open();
mycommand.Fill(ds, "tbl");
myconnect.Close();
// the below assigns the results of the cube query to a dataGridView
// if you drag a dataGridView control to your pallete it will create exactly
// what you need for the line below to work.
// your project type has to be a Window Forms Applications
// this code shown here is in the default Form1.Designer.cs not Form1.cs
dataGridView1.DataSource = new DataView(ds.Tables[0]);
}
private void Quit_Click(object sender, EventArgs e)
{
this.Close();
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button runssas;
private System.Windows.Forms.Button quit;
}
}
是否有更新版本的ADOMD.NET?我唯一能找到的就是[this](http://www.microsoft.com/en-us/download/details.aspx?id=23089),但是這是上傳到2005 – 2013-06-08 04:35:12
,這裏沒有關於多維數據集處理的內容。 – 2013-10-07 08:23:03
回答這個上面已經共享,但公正地分享,我也曾經使用的API相同Microsoft.AnalysisServices指從here下載示例項目從C#處理立方體,但當維數據被改變,那麼你需要處理數據庫而不是立方體。
當服務器上必須模擬最終用戶身份時,您還可以使用連接字符串的EffectiveUserName屬性。
NOTE:要使用EffectiveUserName屬性,調用方必須在Analysis Services中具有管理權限。
您必須處理數據庫,而不是多維數據集。因爲立方體只有尺寸不是內部的尺寸。這可能會導致一些衝突。
要Prozess所有,多維數據集和維度,您必須處理整個數據庫:
Server server = new Server();
server.Connect(cubeConnectionString);
Database database = server.Databases.FindByName(databaseName);
database.Process(ProcessType.ProcessFull);
- 1. SSAS多維數據集處理選項 - 禁用多維數據集
- 2. 錯誤處理多維數據集TFS
- 3. C++多維數據處理
- 4. 日期維度在OLAP多維數據集中停止處理
- 5. 使用SSIS 2005處理SSAS 2012多維數據集
- 6. WebGL多紋理多維數據集
- 7. 作業中的SSAS多維數據集處理失敗
- 8. 如何處理多維數組?
- 9. PHP處理多維$ _REQUEST數組嗎?
- 10. javascript foreach如何處理多維數組?
- 11. OLAP多維數據集 - 數據多維數據集
- 12. 當維數是可變的時,如何處理多維數組?
- 13. OPENQUERY多維數據集查詢在多維數據集處理過程中非常緩慢
- 14. 用於顯示OLAP多維數據集的自由控件
- 15. 如何手動處理Tfs_Analysis OLAP多維數據集?
- 16. 我該如何做OLAP多維數據集增量處理?
- 17. 僅部署多維數據集模式,不進行處理
- 18. 如何處理單個多維數據集分區
- 19. 多維數據處理替代方案
- 20. 使用SQL代理和模擬信息處理OLAP多維數據集
- 21. 如何將多個紋理應用於多維數據集的VBO?
- 22. 處理在二維數組
- 23. 二維數組處理
- 24. 如何使用c#編碼中的xmla處理多維數據集
- 25. 如何使用變量來處理多維數組的元素?
- 26. 使用單維數組中的數據創建多維數組
- 27. 將.txt文件處理成數組,並處理數組數據
- 28. 喂多維數據集
- 29. 多維數據集配置
- 30. 整理多維數組值
感謝您的答覆 – 2010-05-07 05:14:36
我不認爲你需要adomdConnection.Close();因爲你使用using語句。不過,我認爲你應該adomdCommand.Dispose();因爲adomdCommand不在使用聲明中,但我不確定。 – user3711421 2016-01-04 12:32:04
@Meff,你的「服務器」變量正在使用什麼樣的庫? – 2017-07-13 14:19:27