troubleshooting Question

Cannot convert type 'string' to 'Microsoft.AnalysisServices.RelationalDataSource'

Avatar of homeshopper
homeshopperFlag for United Kingdom of Great Britain and Northern Ireland asked on
C#ASP.NET
8 Comments1 Solution795 ViewsLast Modified:
Hi, I am getting the following error:
ds = (Microsoft.AnalysisServices.RelationalDataSource)CreateDataSource(db, strDataSourceName, strStringConnection);//Error      1      Cannot convert type 'string' to 'Microsoft.AnalysisServices.RelationalDataSource' Line:255      18
Thanks in advance for any help given.
For clarity I have listed complete below:
protected void btnGo_Click(object sender, EventArgs e)
    {
        try
        {
            errorLabel4.Text = "";
            lblErr.Text = "";
            System.Web.HttpContext.Current.Response.Write("<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>&nbsp;Yes:GO1:<br/>");
            System.Web.HttpContext.Current.Response.Write("");
            strConn = txtConnStr.Text;
            commandText = txtMDX.Text;
            lblTable.Text = "<font color='Silver'>" + "Ln:227T:btn:" + strConn + "#" + "</font>" + "<font color='green'>" + "&nbsp;&nbsp;&nbsp;&nbsp;cmdT:" + "</font>" + "<font color='Silver'>" + commandText + "#" + "</font>";
            //Microsoft.AnalysisServices.AdomdClient.AdomdConnection svr = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(strConn);
            //svr.Open();
            //Microsoft.AnalysisServices.AdomdClient.AdomdCommand cmd = new Microsoft.AnalysisServices.AdomdClient.AdomdCommand(commandText, svr);
            //<!-- Start Page Content -->            
            System.Web.HttpContext.Current.Response.Write("232:Cube creation process started.<br/>");
            Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
            Microsoft.AnalysisServices.Database db = new Microsoft.AnalysisServices.Database();
            //Microsoft.AnalysisServices.RelationalDataSource ds = new Microsoft.AnalysisServices.RelationalDataSource();
            Microsoft.AnalysisServices.RelationalDataSource ds = new Microsoft.AnalysisServices.RelationalDataSource();
            Microsoft.AnalysisServices.DataSourceView objDataSourceView = new Microsoft.AnalysisServices.DataSourceView();
            DataSet objDataSet = new DataSet();
            Microsoft.AnalysisServices.Dimension[] objDimensions = new Microsoft.AnalysisServices.Dimension[intDimensionTableCount];
            strStringConnection = "Provider=" + strProviderName + ";data source=" + strDBServerName + ";";
            //1) Connect to the Analysis Services :Create a connection of AnalysisServices server.
            //objServer = (Microsoft.AnalysisServices.Server)ConnectAnalysisServices(strDBServerName, strProviderName);
            //static Microsoft.AnalysisServices.Server ServerConnect( String strStringConnection)
            svr = (Microsoft.AnalysisServices.Server)ServerConnect(strStringConnection);
            System.Web.HttpContext.Current.Response.Write("245:ServerConnect(strStringConnection)<br/>");
            //2) Create a Database :Create a database in AnalysisServices server and save it.
            //objDatabase = (Microsoft.AnalysisServices.Database)CreateDatabase(objServer, strCubeDBName);
            //static Microsoft.AnalysisServices.Database CreateDatabase(Microsoft.AnalysisServices.Server svr, String DatabaseName)
            db = (Microsoft.AnalysisServices.Database)CreateDatabase(svr, strCubeDBName);
            System.Web.HttpContext.Current.Response.Write("250:CreateDatabase(svr, strCubeDBName)<br/>");
            //3) Create a DataSource :Add a datasource to the database and set its connection string.
            //objDataSource = (Microsoft.AnalysisServices.RelationalDataSource)CreateDataSource(objServer, objDatabase, strCubeDataSourceName, strDBServerName, strDBName);
            //static string CreateDataSource(Microsoft.AnalysisServices.Database db, string strDataSourceName, string strConnectionString)
            //static object CreateDataSource(Microsoft.AnalysisServices.Database db, string strDataSourceName, string strConnectionString)
            ds = (Microsoft.AnalysisServices.RelationalDataSource)CreateDataSource(db, strDataSourceName, strStringConnection);//Error	1	Cannot convert type 'string' to 'Microsoft.AnalysisServices.RelationalDataSource' Line:255	18
            System.Web.HttpContext.Current.Response.Write("256:CreateDataSource(db, strDataSourceName, strStringConnection)<br/>");
			
            //<!-- End Page Content -->
            System.Web.HttpContext.Current.Response.Write("<br/>&nbsp;End");
        }
        catch (System.Exception ex)
        {
            lblErr.Text = "&nbsp;&nbsp;" + ex.Message;
            errorLabel4.Text = "<font color='red'>" + "err:306E:btn:" + "</font>" + ex.ToString();
        }
    }// End btnGo_Click 
		//http://technet.microsoft.com/en-us/library/ms345093.aspx
        //1) Connect to the Analysis Services :Create a connection of AnalysisServices server.
		//Connecting to the Server Object
		static Microsoft.AnalysisServices.Server ServerConnect( String strStringConnection)
        {
            string methodCaption = "ServerConnect method";
            Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
            try
            {
                svr.Connect(strStringConnection);
            }
            #region ErrorHandling
            catch (Microsoft.AnalysisServices.AmoException e)
            {
                MessageBox.Show( "AMO exception " + e.ToString());
                svr = null;
            }
            catch (Exception e)
            {
                MessageBox.Show("General exception " + e.ToString());
                svr = null;
            }
            #endregion          
            return svr;
        }
        //2) Create a Database :Create a database in AnalysisServices server and save it.
		//Creating, Dropping, and Finding a Database
        static Microsoft.AnalysisServices.Database CreateDatabase(Microsoft.AnalysisServices.Server svr, String DatabaseName)
        {
            Microsoft.AnalysisServices.Database db = null;
            if ( (svr != null) && ( svr.Connected))
            {
                // Drop the database if it already exists
                db = svr.Databases.FindByName(DatabaseName);
                if (db != null)
                {
                    db.Drop();
                }
                // Create the database
                db = svr.Databases.Add(DatabaseName);
                db.Update();
            }          
            return db;
        }
		//3) Create a DataSource :Add a datasource to the database and set its connection string.
		//DataSource Objects
        //static object CreateDataSource(Microsoft.AnalysisServices.Database db, string strDataSourceName, string strConnectionString)
        static string CreateDataSource(Microsoft.AnalysisServices.Database db, string strDataSourceName, string strConnectionString)
        {
                Microsoft.AnalysisServices.Server svr = db.Parent;
                Microsoft.AnalysisServices.DataSource ds = db.DataSources.FindByName(strDataSourceName);
                if (ds != null)
                    ds.Drop();
                // Create the data source
                ds = db.DataSources.Add(strDataSourceName, strDataSourceName);
                ds.ConnectionString = strConnectionString;
                // Send the data source definition to the server.
                ds.Update();
                return ds.Name;
        }
ASKER CERTIFIED SOLUTION
Meir Rivkin
Full stack Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros