Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Create Data Source Using ConnectionString

  • Last UpdatedJun 10, 2024
  • 2 minute read

The following example demonstrates the creation of data source using connection string. The data source created will be listed in the enterprise console and the repository can be created using the newly created data source.

PROCEDURE

Dll REFERENCE

Workflow.NET.NET2

Skelta.Configurations.DB

NAMESPACE USED

Workflow.NET

Skelta.Configurations.DB.Interfaces

Skelta.Configurations.DB

Skelta.FarmManager

Try the following code in a console application by adding the above references and name spaces:

using System;

using Skelta.Configurations.DB.Interfaces;

using Skelta.Configurations.DB;

using Workflow.NET;

using Skelta.FarmManager;

namespace CreateDataSource

{

/// <summary>

/// Sample Class to create Data Source using Connection String

/// </summary>

class CreateDataSourceUsingConnectionString

{

static void Main(string[] args)

{

Test();

}


static void Test()

{

try

{

//Set Connection String

string connectionString = "Data Source=localhost;Integrated Security=True;";


//Provide a new name for the Database

string dataBase = "SampleDataBase";


//Creating a Data Source Object with name dataSource

DataSource dataSource = new DataSource();

 

//Set Name for the Data Source

dataSource.Name = "SampleDataSource";


//Check whether the Data Source Name Exists in Farm Database

DataSourceCollection datasourceCollec = new DataSourceCollection();

if (datasourceCollec.Contains(dataSource.Name))

{

datasourceCollec = null;

throw new Exception("Data Source \"" + dataSource.Name + "\" already exists in Farm Database");

}


//Set Description for Data Source

dataSource.Description = "SampleDataSource";


//Set SourceType for Data Source(SQL=SQL Server)

dataSource.SourceType = "SQL Server";


//Set ConnectionStringXML for the Data Source

dataSource.ConnectionStringXML = "<datasource >" + connectionString + "Database=" + dataBase + "</datasource >";


//Set DataBase handler

IDBCore coreHandler = DBCoreHandler.GetHandler(connectionString, "SQL Server");


//Create a new DataBase with Product Tables

coreHandler.CreateDatabaseWithReadCommittedSnapshot(dataBase);

Console.WriteLine("Database \"" + dataBase + "\" was successfully created");

//Run the Product Script to create Product Tables in DataBase

coreHandler.RunScript(Config.GetConfigFilePath() + "DatabaseScripts\\SQLServer\\Workflow.NET.sql");



//Create a Database Archive with Product Tables

coreHandler = DBCoreHandler.GetHandler(connectionString, "SQL Server");

coreHandler.CreateDatabaseWithReadCommittedSnapshot(dataBase + "_BI");

Console.WriteLine("Database Archive \"" + (dataBase.ToString() + "_BI") + "\" was successfully created");

//Run the Product Script to create Product Tables in DataBase Archive

coreHandler.RunScript(Config.GetConfigFilePath() + "DatabaseScripts\\SQLServer\\Workflow.NET.sql");


//Save the Data Source

dataSource.Save();

Console.WriteLine("DataSource \"" + dataSource.Name + "\" was successfully created in the Farm Database");

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

}


Related Links
TitleResults for “How to create a CRG?”Also Available in