Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

Connecting to Oracle DB using AMO

$
0
0

I'm working on a project which has a part to create a oracle connection to the oracle DB using oracle client and I'm creating the connection like this ,

1. Create the SSAS server

2. Create the Data source 

3.Create the Data source View

Here's the code that I'm using , 

//Create SSAS

 try
            {
               //Connect to the Server

                server = new Server();
                server.Connect(@"data source = localhost");

                //create new DB

                db = new Database("testOra22");
                db = server.Databases.Add("testOra2");
                db.Update();
                datasrc = db.DataSources.FindByName("testOra2");

               
                datasrc = db.DataSources.Add("testOra2", "dsv01");
                // conn.Open();
                datasrc.ConnectionString = @"Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = cmbtrndb02 )( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = hector ) ) ); User Id= trnint16; Password = trnint16;";

                datasrc.Update();

                DataSourceView dsv = null;
                dsv = db.DataSourceViews.Add();
                dsv.DataSourceID = "dsv01";
                dsv.Name = "oraDataSource";
                dsv.Schema = new DataSet();

                //Oracle Connection

                conn.ConnectionString = "Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = trndb02 )( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = goslin) ) ); User Id= abc123; Password = abc123;";

                conn.Open();

                //Add Table

                string sql = "select * from DIMACCOUNT where ACCOUNTKEY<24";

                cmd = new OracleCommand(sql, conn);
                cmd.CommandType = CommandType.Text;

                da = new OracleDataAdapter(cmd);

                da.FillSchema(dsv.Schema, SchemaType.Mapped, "ACCOUNTKEY");

                DataTable[] dts = da.FillSchema(dsv.Schema, SchemaType.Mapped, "ACCOUNTKEY");

                DataTable dt = dts[0];

                //Adding Extended Properties
                dt.ExtendedProperties.Add("TableType", "Table");
                dt.ExtendedProperties.Add("DbSchemaName", "oraCon");
                dt.ExtendedProperties.Add("DbTableName", "DIMACCOUNT");
                dt.ExtendedProperties.Add("Friendly Name", "ACCOUNT");

                dsv.Update();
              
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message.ToString());
            }

Here's the Code for create SSAS Data source View

 try
            {
                //Connecting to the Server
               // datasrc = db.DataSources.FindByName("testOra2");
               // datasrc = db.DataSources.Add("testOra2", "dsv01");
               //// conn.Open();
               // datasrc.ConnectionString = @"Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = trndb02 )( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = goslin) ) ); User Id= abc123; Password = abc123;";
               // datasrc.Update();
                server.Connect(@"Data source= localhost");
                server.Databases.GetByName("testOra2");

                DataSourceView dsv = null;
                dsv = db.DataSourceViews.Add("dsv01");

                dsv.Name = "oraDataSource";
                dsv.Schema = new DataSet();

                //Oracle Connection

                conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = cmbtrndb02 )( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = hector ) ) ); User Id= trnint16; Password = trnint16;";

                conn.Open();

                //Add Table

                string sql = "select * from DIMACCOUNT where ACCOUNTKEY<24";

                cmd = new OracleCommand(sql, conn);
                cmd.CommandType = CommandType.Text;

                da = new OracleDataAdapter(cmd);

                da.FillSchema(dsv.Schema, SchemaType.Mapped, "ACCOUNTKEY");

                DataTable[] dts = da.FillSchema(dsv.Schema, SchemaType.Mapped, "ACCOUNTKEY");

                DataTable dt = dts[0];

                //Adding Extended Properties
                dt.ExtendedProperties.Add("TableType", "Table");
                dt.ExtendedProperties.Add("DbSchemaName", "oraCon");
                dt.ExtendedProperties.Add("DbTableName", "DIMACCOUNT");
                dt.ExtendedProperties.Add("Friendly Name", "ACCOUNT");

                dsv.Update();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());

            }


This code works fine, It is creating the Data source View and Data source as intended but the problem is when I'm using BIDS to explore the SSAS Database (Explore Data action command in Data Source View) It is pop an error. 

TITLE: System.Data
------------------------------

An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.

------------------------------
BUTTONS:

&Retry
Cancel
------------------------------

I've changed the connection string including a provider It is saying that "Provider" is not a valid keyword.

My namespaces are, 

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

Thanks,

 

Viewing all articles
Browse latest Browse all 2472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>