on 04-11-2017 1:26 PM - last edited on 02-03-2024 11:29 PM by postmig_api_4
I am trying to change my current logged in user from B1 using Add ons but getting some issue. Is I disconnect my current logged in user and company from b1 ?
public static SAPbobsCOM.Company oCompany;
public static SAPbobsCOM.Company otherCompany = new SAPbobsCOM.Company();
oCompany = ((SAPbobsCOM.Company)SBO_Application.Company.GetDICompany());
if (oCompany.Connected)
{
changedb();
}
private void changedb(){
Program.otherCompany.Server = Program.oCompany.Server;
Program.otherCompany.CompanyDB = Program.oCompany.CompanyDB;
Program.otherCompany.UserName = User.ToString();
Program.otherCompany.Password = pwd.ToString();
Program.otherCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
Program.otherCompany.DbUserName = Program.oCompany.DbUserName;
Program.otherCompany.DbPassword = Program.oCompany.DbPassword;
Program.otherCompany.UseTrusted = true;
Program.otherCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
string error = string.Empty;
int iErr;
if (Program.otherCompany.Connect() != 0)
{
Program.oCompany.GetLastError(out iErr, out error);
if (iErr == -111)
{
Application.SBO_Application.MessageBox("Wrong database password");
}
else if (iErr == -107)
{
Application.SBO_Application.MessageBox("Wrong company password");
}
else
{
Program.SBO_Application.StatusBar.SetText("thrads error" + Program.oCompany.GetLastErrorDescription() + Program.oCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
}
else
{
//Connected
Program.SBO_Application.StatusBar.SetText("Connected", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
}
//throw new System.NotImplementedException();
}
Hi Dhruv,
As I said in your previous post, this line should not work on your method:
Program.otherCompany.DbPassword = Program.oCompany.DbPassword;
As you see, this property returns "*****", the SDK does not provide the correct password for security reasons. Remove the lines:
Program.otherCompany.DbUserName = Program.oCompany.DbUserName;
Program.otherCompany.DbPassword = Program.oCompany.DbPassword;
And use this :
Program.otherCompany.UseTrusted = true;
I noted another situation on your code. You specify the server type as HANA,the previous database is not a hana database?
About your error. On your changedb function, you use this instruction:
Program.SBO_Application.StatusBar.SetText("thrads error" + Program.oCompany.GetLastErrorDescription() + Program.oCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
But the correct is this:
Program.SBO_Application.StatusBar.SetText("thrads error" + Program.otherCompany.GetLastErrorDescription() + Program.otherCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
If your code doesn't work after the changes, try run separately the sample below:
public SAPbobsCOM.Company oCompany;
public SAPbouiCOM.Application oApplication;
public SAPbobsCOM.Company oOtherCompany = new SAPbobsCOM.Company();
private void conectApp()
{
var oSboGuiApi = new SAPbouiCOM.SboGuiApi();
oSboGuiApi.Connect("0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056");
oApplication = oSboGuiApi.GetApplication(-1);
oCompany = ((SAPbobsCOM.Company)oApplication.Company.GetDICompany());
if (oCompany.Connected)
{
changedb("provide your user", "provide your password");
}
}
private void changedb(string user, string password)
{
oOtherCompany.Server = oCompany.Server;
oOtherCompany.CompanyDB = oCompany.CompanyDB;
oOtherCompany.UserName = user;
oOtherCompany.Password = password;
oOtherCompany.DbServerType = oCompany.DbServerType;
oOtherCompany.LicenseServer = oCompany.LicenseServer;
oOtherCompany.UseTrusted = true;
oOtherCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
string error = string.Empty;
int iErr;
if (oOtherCompany.Connect() != 0)
{
oOtherCompany.GetLastError(out iErr, out error);
if (iErr == -111)
{
oApplication.MessageBox("Wrong database password");
}
else if (iErr == -107)
{
oApplication.MessageBox("Wrong company password");
}
else
{
oApplication.StatusBar.SetText("thrads error" + oOtherCompany.GetLastErrorCode() + oOtherCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
}
else
{
//Connected
oApplication.StatusBar.SetText("Connected", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
}
}
The code above works fine for me. I have tested on SAP B1 9.1 PL 13.
Hope it helps.
Kind Regards,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi DIEGO LOTHER
Thank you for solving my problem. Same problem had as you mentioned in you answer.
User | Count |
---|---|
98 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.