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

AVEVA™ Work Tasks

Subscribe AssemblyResolve Event while Using APIs for Database-related Activities

Subscribe AssemblyResolve Event while Using APIs for Database-related Activities

  • Last UpdatedJun 10, 2024
  • 2 minute read

If any of the applications use AVEVA Work Tasks APIs for doing some database related activities, then the following code has to be used before calling the API.

Note: If the following code is not added then the following error message is displayed.

Code

AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs e)

{

AssemblyName requestedName = new AssemblyName(e.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;

}

};


Example:

If the below API is used to create a data source, then the above code sample has to be used before calling the CreateDatasource() method.

Using Assembly resolve event

AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs e)

{

AssemblyName requestedName = new AssemblyName(e.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;

}

};

HandleSkeltaFarm handlerSkeltaFarm = new HandleSkeltaFarm();

Skelta.FarmConfiguration.HandleSkeltaFarm.ConnectionStringDetails connectStrDetails = new HandleSkeltaFarm.ConnectionStringDetails();

connectStrDetails.DataSource = "serverName";// Server name

connectStrDetails.DatabaseType = "SQL Server";

connectStrDetails.IntegratedSecurity = true;// true if Windows authentication is used

connectStrDetails.DatabaseName = "DataBaseName";// Database name handlerSkeltaFarm.PrepareConnectionString(connectStrDetails);

handlerSkeltaFarm.CreateDatasource("DataSourcename", "Datasource description");


Without using Assembly resolve event

HandleSkeltaFarm handlerSkeltaFarm = new HandleSkeltaFarm(); Skelta.FarmConfiguration.HandleSkeltaFarm.ConnectionStringDetails connectStrDetails = new HandleSkeltaFarm.ConnectionStringDetails();

connectStrDetails.DataSource = "serverName";// Server name

connectStrDetails.DatabaseType = "SQL Server";

connectStrDetails.IntegratedSecurity = true;// true if Windows authentication is used

connectStrDetails.DatabaseName = "DataBaseName";// Databse name

handlerSkeltaFarm.PrepareConnectionString(connectStrDetails);

handlerSkeltaFarm.CreateDatasource("DataSourcename", "Datasource description");


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