07-05-2015 11:18 AM
Hello MEGA people !
I am trying to build a VB Application to be able to do some tasks in MEGA.
I managed to connect to mega but with direct interaction needed with the Environment to enter the credentials.
How can I do supply the user and password to MEGA without direct interaction with MEGA ? (so I can open a transcation do changes and dispatch)
Here is my trial where I tried to create a transaction but didn't know how to supply the username and the password, and I wish you can help me in this
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Solved! Go to Solution.
12-05-2015 09:48 AM
Thanks FBoulart for your Reply.
Thanks Leslie ! what you sent as a solution worked
I did some modification to fit and work onHOPEX V1R2
Find it below :
Dim sAdmUser = "Administrator" Dim sAdmPwd = "" Dim sUser = "MEGA" Dim sPwd = "" Dim sEnvPath = "C:\...\EnvName" Dim sRepository = "RepoName" 'Dim oMegaApp = CreateObject("Mega.Application") Dim oMegaApp As New MegaMapp.MegaApplication Dim oEnvironment = oMegaApp.Environments.item(sEnvPath) 'open environment in update mode oEnvironment.CurrentAdministrator = sAdmUser oEnvironment.CurrentPassword = sAdmPwd 'Msgbox "Environment opened in update mode: " & oEnvironment.Name Dim lTransactions = oEnvironment.Transactions Dim oTransaction = lTransactions.Create(sRepository, sUser) oTransaction.Password = "" 'Msgbox "Transaction: " & oTransaction.Name 'get root Dim MyRoot = oTransaction.Database.Open 'perform data update Dim oObject = MyRoot.GetCollection("Org-unit").Add("MyAppCreatedOrgunit") MsgBox("Object created: " & oObject.Name) MyRoot.MegaCommit() 'close root MyRoot.BaseClose() 'to dispatch transaction oTransaction.Dispatch(True) 'free collections MyRoot = Nothing lTransactions = Nothing 'oObject = Nothing oTransaction = Nothing
09-05-2015 10:25 PM
Hello
@FBoulart : Your code connects in admin mode which means you block the system database so noone can connect or dispatch duing your script, and I think the original request was for code to connect in transaction mode.
@Mostafafad:
A KB article exists on this topic : solution number 415 "API: Connect in transaction mode (example VB Script)"
http://community.mega.com/t5/custom/page/page-id/mega-kb-solution?sid=50120000000mqSCAAY
Here is the sample code:
sAdmUser = "Administrator"
sAdmPwd = ""
sUser = "User"
sPwd = ""
sEnvPath = "C:\MEGA_Data\Demonstration"
sRepository= "Adventure"
Set oMegaApp = CreateObject("Mega.Application")
Set oEnvironment=oMegaApp.Environments.item(sEnvPath)
'open environment in update mode
oEnvironment.CurrentAdministrator = sAdmUser
oEnvironment.CurrentPassword = sAdmPwd
'Msgbox "Environment opened in update mode: " & oEnvironment.Name
Set lTransactions = oEnvironment.Transactions
Set oTransaction = lTransactions.Create(sRepository,sUser)
oTransaction.Password = ""
'Msgbox "Transaction: " & oTransaction.Name
'get root
Set MyRoot = oTransaction.Database.Open
'perform data update
Set oObject = MyRoot.GetCollection("Org-unit").Add("MyOrgunit")
Msgbox "Object created: " & oObject.Name
MyRoot.MegaCommit
'close root
MyRoot.BaseClose
'to dispatch transaction
oTransaction.Dispatch
'you can alternatively discard transaction
oTransaction.Abort
'you can alternatively refresh transaction
oTransaction.Refresh
'free collections
Set MyRoot = Nothing
Set lTransactions = Nothing
Set lUsers = Nothing
Set lRepositories = Nothing
Set oUser = Nothing
Set oObject = Nothing
Set oTransaction = Nothing
regards,
Leslie
07-05-2015 01:41 PM - edited 07-05-2015 01:42 PM
Hi Mostafad, You can try something like.
This example is about triggering Logical backup.
Hope that helps.
Set oMegaApp = CreateObject("Mega.Application")
' path to environment must be as listed in Mega Administrator
Set oEnvironment = oMegaApp.Environments.Item("\Env_Path")
oEnvironment.CurrentAdministrator = "USR"
oEnvironment.CurrentPassword = "PWD"
Set oDatabase = oEnvironment.Databases.Item("SystemDb")
oDatabase.LogicalSave sSysBackupPath, "DumpObjectsOfMerging = On"
Set oDatabase = oEnvironment.Databases.Item("Development")
oDatabase.LogicalSave sDevBackupPath, "DumpObjectsOfMerging = On"