cancel
Showing results for 
Search instead for 
Did you mean: 

Access denied with DI and C#

Former Member
0 Kudos

Hello,

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)

{

try

{

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

Try

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

thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Angel,

I copy/paste your code and obtain the error code -116, and was for you connect two times consecutively, remove one and connect perfectly.

Best regards.

Former Member
0 Kudos

Hi

put this after vCompany.UseTrusted=false

vCompany.licenseserver=yourlicenseServer

if (vCompany.connected)

{

vCompany.disconnect

}

Hope it helps you

Kind Regards

Salvador Biot

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello

I too copy/paste (like David) in a new project C#, and it works, then I make a DLL with the same code and too works, BUT the same DLL doesn't work into a Web Service.

I think that is the problem, because my main project is a Web Service.

thanks

Former Member
0 Kudos

The ASP_NET USER, NETWORKSERVICE GROUP has no right to access the the Databse (through SAPBobsCOM object). You have to pass it to a Windows Service, I guess.

Former Member
0 Kudos

I also program in C#, this is my code, works like a charm...

<b>Code (C#)</b>


SboGuiApi = new SAPbouiCOM.SboGuiApiClass();
ConnectionString = Environment.GetCommandLineArgs().GetValue(1).ToString();
SboGuiApi.Connect(ConnectionString);
SAPbouiCOM.Application SBO_Application = SboGuiApi.GetApplication(0);