//using System.Data.SqlClient;
class BYODConnection
{
// private DMFDataSource dmfDataSource
// /// <summary>
// /// Runs the class with the specified arguments.
// /// </summary>
// /// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
boolean issuccess;
str connectionstr;
DMFDataSource dmfdb = DMFDataSource::find("BYOD10");
if(dmfdb)
{
issuccess = DMFDataSource::validateEntityConnectionString(dmfdb);
}
else
{
CryptoBlob encryptedCryptoBlob;
str value = "Data Source=serverName,1433; Initial Catalog=DB; Integrated Security=False; User ID=USer; Password=Passwrd";
// encrpyt the connection string
encryptedCryptoBlob = WinAPIServer::cryptProtectData(str2cryptoblob(value));
dmfdb.SourceName = "BYOd10";
dmfdb.Type = DMFSourceType::EntityDB;
dmfdb.Description = 'D365 to AZure Sql';
dmfdb.EnableTargetTriggers = NoYes::Yes;
dmfdb.insert();
if(dmfdb)
{
Common common = dmfdb;
connectionstr = appl.EncryptToStringForPurpose(value, common.encryptionPurpose(fieldNum(DMFDataSource, EntityStoreConnectionString)));
info(strFmt("%1",connectionstr));
ttsbegin;
dmfdb.selectForUpdate(true);
dmfdb.EntityStoreConnectionString = connectionstr;
dmfdb.update();
ttscommit;
issuccess = DMFDataSource::validateEntityConnectionString(dmfdb);
}
}
if(issuccess)
{
Info("Done");
}
else
{
Error("Failed");
}
}
}
No comments:
Post a Comment