cancel
Showing results for 
Search instead for 
Did you mean: 

confused about connection string

Former Member
0 Kudos

Hello, I'm currently developing an external .NET application that 'handles' the SAP B1 UI API:
it opens certain menus and looks for exisiting documents in the SAP B1 client on the current computer.

This all works fine when I'm doing this in debug, and even in release locally where I use the 'debug' connection string.

My questions and confusion are about this connection string:

When one develops an add-on and uses it SAP B1 provides the connection string via command line to the addon.

Since my application is external however and not run internally as an addon, I wonder if there is a way to get this connectionstring from SAP B1 without reading it out via code through a custom written add-on?

Is it necessary or should it just stay the same?

Should I just keep using the debug connection string, even at client's local machine?

Keep in mind that this application is not meant as an addon it just uses the SAPbouicCOM.SboGuiApi & SAPboiCOM.Application to open some standard menus and do some actions (like lookups) in those menus.

Any clarification would be greatly appreciated.

Friendly greetings,

Pieterjan

Accepted Solutions (1)

Accepted Solutions (1)

maik_delly
Active Contributor
0 Kudos

Hi Pieterjan,

just to clear things up :

The connection string is supplied only for an installed and started addon as startparameter from SBO client .

In your case you don't get a parameter ( addon is external ) - therefor you have always to use the debug connection string "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"

to connect to UI.

There is no way to get an other connection string to use in your external program.

regards,

Maik

Former Member
0 Kudos

And this is what I wanted to know.

Thanks for clearing that up, Maik.

I've marked your answer as the correct one.

Answers (3)

Answers (3)

Johan_H
Active Contributor
0 Kudos

Hi Pieterjan,

Just out of curiosity, you have a stand alone .windows application, and you are accessing the B1 client from it. Why, is there something you can not do through the DI API ? If you need to show the user something in the B1 client, or if you need to prefill some information or something, why not create an addon ?

I ask, because several years ago, a colleague of mine had built a similar solution, which I later discovered was done because he didn't know that he could use certain functionality through the DI API as well.

Regards,

Johan

Former Member
0 Kudos

Hi Johan,

Yeah, I'm well aware of the DI API.

Basically what the application does is make a number of documents through the DI API

The document numbers are then stored in a custom table and used to direct the end-user to these documents (using the UI api) if he wishes to do so.

Thanks for the helpful suggestion.

Former Member
0 Kudos

Hi,

This code was adapted from SAP SDK examples.

For more information about ConnectionString, recommend you read and view the 'New UI DI Connection' example, in: C:\Program Files (x86)\SAP\SAP Business One SDK\Samples\COM UI DI\CSharp.


private SAPbouiCOM.Application SBO_Application;

        private SAPbobsCOM.Company oCompany;

      

        private void SetApplication()

        {

          

            //*******************************************************************

            // Use an SboGuiApi object to establish connection

            // with the SAP Business One application and return an

            // initialized appliction object

            //*******************************************************************

          

            SAPbouiCOM.SboGuiApi SboGuiApi;

            string sConnectionString;

          

            SboGuiApi = new SAPbouiCOM.SboGuiApi();

          

            // by following the steps specified above, the following

            // statment should be suficient for either development or run mode

          

            var sConnectionString = aEnvironmentArguments.Length == 2

                ? aEnvironmentArguments.GetValue(1).ToString();

                : "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";

            // connect to a running SBO Application

          

            SboGuiApi.Connect(sConnectionString);

          

            // get an initialized application object

          

            SBO_Application = SboGuiApi.GetApplication(1);

            }

    }

Regards,

Paulo Henrique

AdKerremans
Active Contributor
0 Kudos

Hi,

I always check at the start of my addons if there is a parameter.

If yes then I use it.

If no then I set the debug connectionstring as my connection string.

This way I don't have to pass the connection string as parameter in my projects.

See my sample code below.

if (Environment.GetCommandLineArgs().GetUpperBound(0) > 0)

{

  sConnectionString = (String)Environment.GetCommandLineArgs().GetValue(1);

}

else

{

  sConnectionString = "0030002c0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";

}

Regards

Ad

Former Member
0 Kudos

Ad, as stated before: I'm talking about an external .NET application here, it is not run as an add-on! It's just a standalone .NET application that runs on the same machine.

AdKerremans
Active Contributor
0 Kudos

Hi Pieterjan,

This also works for stand alone applications, when an application uses the UI-api it is treated as an addon.

Regards

Ad

Former Member
0 Kudos

Hi Ad. Thanks for helping out.

I just tested this to make sure (it's a winforms application btw):

and

            Dim i = System.Environment.GetCommandLineArgs().Length

            Dim Value1 = System.Environment.GetCommandLineArgs(0)

Only returns as length 1 and the argument at position 0 is the path the application is running in.

There's no second argument (which would be the connection string if it's run as an addon in SAP)

So the connection string does not get passed in anyway whatsoever (I wonder how it would)

If I'm doing something wrong please correct me.

Kind regards,

Pieterjan

AdKerremans
Active Contributor
0 Kudos

Hi Pieterjan,

The connection string is only passed when the application is started by SAP.

What I do is: if there is no connection string (length = 1), I set the connection string myself.

and the application wil automatically connect to the running SAP Client.

Regards

Ad

Former Member
0 Kudos

I see.
Where do you get/derive this connection string from when you have to set it manually yourself?

AdKerremans
Active Contributor
0 Kudos

It's a standard string coming from SAP.

You can use the one in my code and hardcode it.

Regards

Ad