Skip to Content
Former Member
Jul 18, 2005 at 02:48 PM

Access denied with DI and C#



I can connect with VB.NET, but I cant do it with C#.

I was traslated the sintax of same code in each language, but doens't work.

Also, I was include one VB project into my .NET solution, but the same function that work at VB.NET solution, called from my project C# doesn't work.

¿any idea?, thanks

the code C#:



private SAPbobsCOM.Company ConnectDataBase(string dbName)




Company vCompany ;

int lRetCode;

int lErrCode;

string sErrMsg;

vCompany = new SAPbobsCOM.Company();

vCompany.Server = "(local)";

vCompany.CompanyDB = dbName;

vCompany.UserName = "manager";

vCompany.DbUserName = "sa";

vCompany.DbPassword = "";

vCompany.Password = "manager";

vCompany.language = SAPbobsCOM.BoSuppLangs.ln_Spanish;

vCompany.UseTrusted = false;

lRetCode = vCompany.Connect();

lRetCode = vCompany.Connect();

if(lRetCode != 0)

vCompany.GetLastError(out lErrCode, out sErrMsg);

return vCompany;


catch(Exception ex)


string mess = ex.Message ;

return null;



the code VB:



Public Function ConnectDataBase(ByVal dbName As String) As SAPbobsCOM.Company

Dim vCompany As SAPbobsCOM.Company

Dim lRetCode, lErrCode As Long

Dim sErrMsg As String

Dim strCookie As String

Dim strConnectionContext As String


vCompany = New SAPbobsCOM.Company

vCompany.Server = "(local)"

vCompany.CompanyDB = dbName

vCompany.UserName = "manager"

vCompany.DbUserName = "sa"

vCompany.DbPassword = ""

vCompany.Password = "manager"

vCompany.language = SAPbobsCOM.BoSuppLangs.ln_Spanish

vCompany.UseTrusted = False

lRetCode = vCompany.Connect

If lRetCode <> 0 Then

vCompany.GetLastError(lErrCode, sErrMsg)

End If

Return vCompany

Catch ex As Exception

Return Nothing

End Try

End Function