Server Side API to get connection string or URL

From the Server side API, how do I get the connection string (i.e. Server, SQL Database)?  I need it to execute custom SQL code that joins data from another database.

From the Client Side, I can use 

var url = aras.getServerBaseURL();
var base = aras.getBaseURL();

But these functions are not available from the Sever Side API

I feel I am on the right right track with

dim scb as object = inn.getConnection

dim oInnDatabase as object = scb.CCO.DB.InnDatabase '.databaseName

dim fooDatabaseServerName as object = oInnDatabase.DatabaseServerName 'Works: Gives SBIWS457

Examining the properties in Visual Studio Watch, I found the exact place I want to be, but am unable to access the properties

olnnDatabase.ActiveInteractor.CurrentConnection.ConnectionString '(Failes)

This seems like it should be simple, but I can't seem to find any reference to functions that call back to the initiating server from the Server Side API.

Kent

  • Hi Kent

    You can try below C# code

    Innovator innovator = this.getInnovator();
    IServerConnection connection = innovator.getConnection();
    string dbName = connection.GetDatabaseName(); //Database Name
    string protocol = HttpContext.Current.Request.Url.Scheme; // HTTP or HTTPS
    string serverName = HttpContext.Current.Request.Url.Host; // Server Name
    string appName = HttpContext.Current.Request.Url.Segments[1]; // Application Name
    string appURL = protocol + "://" + serverName + "/" + appName; // Application URL
    return this;

    Thank You

    Gopikrishnan R

  • Converting to vb.net, I am able to get this to work.  Thank you.  (I was missing HttpContext.Current.Request.Url)

    dim connection2 as IServerConnection = inn.getConnection()

    dim dbName2 as string = connection2.GetDatabaseName() 'Database Name
    dim protocol as string = HttpContext.Current.Request.Url.Scheme '; // HTTP or HTTPS
    dim serverName as string = HttpContext.Current.Request.Url.Host '; // Server Name
    dim appName as string = HttpContext.Current.Request.Url.Segments(1) '; // Application Name
    dim appURL as string = protocol + "://" + serverName + "/" + appName '; // Application URL

    Thank you.  This was very helpful and I am no longer stalled out.

  • One more thing. It would be helpful for me to get the SQL database name and the SQL Server Name from the API.  This is also useful for joining tables from another database on the same server or linked databases.  

  • It works great except for one thing.

    I have a server-side c# method attached to OnAfterAdd event of "Activity2 Comment" ItemType. This method should send emails to all active activity assigne if someone adds new comment to activity. Method inserts links to activity and project into message body and thus I need server hostname to generate these links. I'm using CCO.Request.Url.Host to get server hostname. AFAIK it same as HttpContext.Current.Url.Host.

    All works fine until user attaches the file to comment in "Activity Completion Worksheet" form. In this case Url.Host for some reason becomes "localhost" and all my links becomes broken.

    Can anyone explain why this is happening and how to fix it?

    You can easy reproduce it. Just create server-side method with one line code:

    return this.getInnovator().newError(HttpContext.Current.Request.Url.Host);

    attach it to onAfterAdd server event to "Activity2 Comment" itemtype, open Activity Completion Worksheet, add comment, attach file to it and save activity. You'll see popup with "localhost" instead of server hostname.