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

AVEVA™ Work Tasks

Step 1: Create Data Source for the Repository

  • Last UpdatedJun 10, 2024
  • 2 minute read

The following example demonstrates the creation of a data source using a 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

Skelta.FarmConfiguration.dll

Workflow.NET.NET2.dll

NAMESPACE USED

Skelta.FarmConfiguration;

Skelta.FarmManager;

System.Collections.Generic;
System.Reflection;

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

//Need to handle assembly resolve event for appdomain if database used is SQL Server 2005

System.AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

//Build the connection string for repository data source

Skelta.FarmConfiguration.HandleSkeltaFarm.ConnectionStringDetails

connectionStringDetails = new HandleSkeltaFarm.ConnectionStringDetails();

connectionStringDetails.DataSource = "SkeltaNB30";  // System name

connectionStringDetails.DatabaseName = "RepoDatabase";

connectionStringDetails.DatabaseType = "SQL Server";

connectionStringDetails.IntegratedSecurity = false; //For SQL Server Authentication it is  False ; For Windows Authentication it is true

connectionStringDetails.UserId = "sa";

connectionStringDetails.Password = "XXX"; //Enter correct password

HandleSkeltaFarm handlerSkeltaFarm = new HandleSkeltaFarm();

handlerSkeltaFarm.PrepareConnectionString(connectionStringDetails);

//Parameters passed are data source name & description

handlerSkeltaFarm.CreateDatasource("SkeltaDatasource", "data source created for repository");


static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)

{

AssemblyName requestedName = new AssemblyName(args.Name);

if (requestedName.Name.Contains("Microsoft.SqlServer.ConnectionInfo"))

{

if (requestedName.Version.ToString() == "9.0.242.0")

{

throw new Exception("Can not load 9.0.242.0 dll too");

}

else

{

AssemblyName loadThis = new AssemblyName("Microsoft.SqlServer.ConnectionInfo");

loadThis.Version = new Version("9.0.242.0");

loadThis.CultureInfo = requestedName.CultureInfo;

loadThis.SetPublicKeyToken(requestedName.GetPublicKeyToken());

return Assembly.Load(loadThis);

}

}

else

{

if (requestedName.Name.Contains("Microsoft.SqlServer.Smo"))

{

if (requestedName.Version.ToString() == "9.0.242.0")

{

throw new Exception("Can not load 9.0.242.0 dll too");

}

else

{

AssemblyName loadThis = new AssemblyName("Microsoft.SqlServer.Smo");

loadThis.Version = new Version("9.0.242.0");

loadThis.CultureInfo = requestedName.CultureInfo;

loadThis.SetPublicKeyToken(requestedName.GetPublicKeyToken());

return Assembly.Load(loadThis);

}

}

else

return null;

}

}

Verification:

The above code creates a database named RepoDatabase. The entry in Farm DB can be verified in database by running the query Select * from SKDataSource Where Name='SkeltaDatasource'. The same can be verified in Central Config data source list page.

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