Programming SQL Server AMO for Oracle with C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im working on a project which has a part to create a oracle connection to the oracle DB using oracle client and Im creating the connection like this ,
1. Create the SSAS server
2. Create the Data source
3.Create the Data source View
Heres the code that Im using , //Create SSAS Instance

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();
conn.ConnectionString = "Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = trndb)( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = gosin) ) ); User Id= abc123; Password = abc123;";

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 = trndb)( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = gosin) ) ); 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());
}//Create DSV

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 = hector ) ) ); 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 = "Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = trndb)( PORT = 1521 ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = gosin) ) ); 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());

}

This code works fine, It is creating the Data source View and Data source as intended but the problem is when Im 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
------------------------------

Ive 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,


View the full article
 
Back
Top