当前位置:编程学习 > C#/ASP.NET >>

关于用C#调用在SQL Server2005创建以及处理挖掘模型的语句问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.AnalysisServices;
using System.Data.OleDb;


namespace BIApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Server server = new Server();
            server.Connect("localhost");
            Database db = server.Databases["AdventureWorksDW"];
            MiningStructure ms = db.MiningStructures["ASSO"];
            ms.Process(ProcessType.ProcessFull);
            listBox1.Items.Clear();
            listBox1.Items.Add("挖掘结构已处理");
            server.Disconnect();
        }

        
        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            Server server = new Server();
            server.Connect("localhost");
            Database db = server.Databases["AdventureWorksDW"];
            if (db.MiningStructures.Find("ASSO")!=null)
            {
                db.MiningStructures.Remove("ASSO");
                db.Update();
            }
            MiningStructure ms=new MiningStructure("ASSO","ASSO");
            ms.Source=  new DataSourceViewBinding("Adventure Works DW");
         ScalarMiningStructureColumn CustomerKey = new ScalarMiningStructureColumn("CustomerKey", "CustomerKey");
           CustomerKey.Type = MiningStructureColumnTypes.Long;
          CustomerKey.IsKey = true;
          CustomerKey.Content = MiningStructureColumnContents.Key;
           CustomerKey.KeyColumns.Add("DimCustomer", "CustomerKey", OleDbType.Integer);
           ms.Columns.Add(CustomerKey);

          ScalarMiningStructureColumn TotalChildren = new ScalarMiningStructureColumn("TotalChildren", "TotalChildren");
           TotalChildren.Type = MiningStructureColumnTypes.Long;
        // idcol1.IsKey = true;
            TotalChildren.Content = MiningStructureColumnContents.Discrete;
            TotalChildren.KeyColumns.Add("DimCustomer", "TotalChildren", OleDbType.TinyInt);
            ms.Columns.Add(TotalChildren);

            ScalarMiningStructureColumn YearlyIncome = new ScalarMiningStructureColumn("YearlyIncome", "YearlyIncome");
            YearlyIncome.Type = MiningStructureColumnTypes.Long;
        //    idcol2.IsKey = true;
            YearlyIncome.Content = MiningStructureColumnContents.Discrete;
            YearlyIncome.KeyColumns.Add("DimCustomer", "YearlyIncome", OleDbType.Currency);
            ms.Columns.Add(YearlyIncome);
            
            db.MiningStructures.Add(ms);
            ms.Update();
            
            listBox1.Items.Add("挖掘结构已创建");

            MiningModel mm=ms.CreateMiningModel(true,"Asso Mining");
            mm.Algorithm= "Microsoft_Association_Rules";
            double minsup;
            try
            {
                minsup=Convert.ToDouble(textBoxMinSup.Text);

            }
            catch{minsup=0.01;}
            
            double minpro;
            try
            {
                minpro=Convert.ToDouble(textBoxMinPro.Text);
            }
            catch{minpro=0.3;}
            
            int maxset;
            try
            {
                maxset=Convert.ToInt32(textBoxMaxSet.Text);
            }
            catch{maxset=0;}
            mm.AlgorithmParameters.Add("MINIMUM_SUPPORT",minsup);
            mm.AlgorithmParameters.Add("MINIMUM_PROBABILITY",minpro);
            mm.AlgorithmParameters.Add("MAXIMUM_ITEMSET_SIZE",maxset);
            mm.Columns["CustomerKey"].Usage ="Key";
            mm.Columns["TotalChildren"].Usage = "Predict";
            mm.Columns["YearlyIncome"].Usage = "PredictOnly";
 
            mm.Update();
            listBox1.Items.Add("挖掘模型已创建");
            server.Disconnect();
        }
    }
}
以上是我的程序,挖掘结构和挖掘模型的创建都没问题,可是在处理模型时却总报错,错误如下:



未处理 Microsoft.AnalysisServices.OperationException
  Message="高级关系引擎中存在错误。 数据源视图未包含“DimCustomer”表或视图的定义。可能是尚未设置 Source 属性。\n"
  Source="Microsoft.AnalysisServices"
  StackTrace:
       在 Microsoft.AnalysisServices.AnalysisServicesClient.SendExecuteAndReadResponse(ImpactDetailCollection impacts, Boolean expectEmptyResults, Boolean throwIfError)
       在 Microsoft.AnalysisServices.AnalysisServicesClient.Process(IMajorObject obj, ProcessType type, Binding source, ErrorConfiguration errorConfig, WriteBackTableCreation writebackOption, ImpactDetailCollection impact)
       在 Microsoft.AnalysisServices.Server.Process(IMajorObject obj, ProcessType processType, Binding source, ErrorConfiguration errorConfig, WriteBackTableCreation writebackOption, XmlaWarningCollection warnings, ImpactDetailCollection impactResult, Boolean 易做图yzeImpactOnly)
       在 Microsoft.AnalysisServices.Server.SendProcess(IMajorObject obj, ProcessType processType, Binding source, ErrorConfiguration errorConfig, WriteBackTableCreation writebackOption, XmlaWarningCollection warnings, ImpactDetailCollection impactResult, Boolean 易做图yzeImpactOnly)
       在 Microsoft.AnalysisServices.ProcessableMajorObject.Process(ProcessType processType, ErrorConfiguration errorConfiguration, XmlaWarningCollection warnings)
       在 Microsoft.AnalysisServices.ProcessableMajorObject.Process(ProcessType processType)
       在 BIApplication1.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\Administrator\桌面\Form1.cs:行号 27
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 BIApplication1.Program.Main() 位置 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\BIApplication\BIApplication1\Program.cs:行号 17
       在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
希望大家能帮帮我,谢谢



ms.Process(ProcessType.ProcessFull);报错的是这一行 --------------------编程问答-------------------- 我也遇到了同样的问题,怎么解决呀? --------------------编程问答-------------------- 请问最后如何解决,我也遇到同样的问题,希望高手指点一二,不胜感激~~~~
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,