Which database are you logged into?

In a conference like Direcionts EMEA, I noticed again how interested people can be in sometimes such a simple solution. In our company, we implement every installation with a default set of tools (enhancements). One of these tools is a very simple and little something called "Database Info"-form.

The goal is to differentiate what kind of database you logged in: Test Database, a Test Company, a Development Database, ... . Actually, you just want a visual difference between two environments. In the old days (version 3.X and less), we had a menu, which we could give a certain color, caption or whatever. Now, we don't have a form that pops up, so no form we can modify. I present to you a little solution that might be able to help you with this, and the end result looks like this:

The red area, just right from the menu suite, is the "solution" I'm talking about - in case it was not clear Wink. To accomplish the main idea, there are only three things you have to do:

  • Create a form with these properties:
    • Borderstyle: None
    • CaptionBar: None
    • Mimizable: No
    • Maximizable: No
    • Sizeable: No
    • Editable: No
    • Xpos: 0
    • Ypos: 0
  • You put some descriptions on the form with captions.
  • In CodeUnit 1 in Trigger "CompanyOpen" you call the form like:

    IF GUIALLOWED THEN FORM.RUN(FORM::"Database Info");

That's basically all. Easy, isn't it?

But let's make it somewhat more useful and generic. Let's put some info on the form, work with colors and make that configurable ... So that the result is somewhat more like above:

  • Create a setup table with these fields:
    • Primary Key (Code)
    • Show Database info Form (Boolean): use this field to be able to switch off the use of the form.
    • Title (Text): Will be shown on the form.
    • Color (Option): The color of the form to make it even more "visible". I have chosen to make it simple. Just a fixed number of colors with an option field. You could make this with a color picker, but hey, we're not creating a business critical form here, are we Wink?
  • Modify codeunit 1, change your already added code to:

    CLEAR(recDatabaseInfoSetup);
      IF recDatabaseInfoSetup.GET THEN
        IF recDatabaseInfoSetup."Show Database Info Form" THEN
          IF GUIALLOWED THEN
            FORM.RUN(FORM::"Database Info");

  • Modify the form like this:

    The main idea is to "generate" the form when we are opening it. We'll set the colors, fill in the fields, make the form the right size and put it in it's place. Actually, the design on the form might even look like this (it doesn't matter):

    • To make the colors work:
      • For all colors in your option field, create a shape and put it somewhere on your form. Also, give a name to your shapes (preferably the color names to make the code more readable);
      • Create a function "SetBackColor" and call it "OnOpenForm".
      • This is what your function "SetBackColor" could look like;

        SetBackColor()

        //FIXED WIDTH AND HEIGHT. I CHOSE THESE VALUES:
        lintFormWidth := 10960;
        lintFormHeight := 4647;    

        //RESET SHAPE VALUES
        CurrForm.Blue.VISIBLE:=FALSE;
        CurrForm.Red.VISIBLE:=FALSE;
        //...
        //YOU CAN ADD THE REST OF THE COLORS IN THE SAME WAY

        //MOVE SHAPES
        CASE recDatabaseInfoSetup.Color OF
          recDatabaseInfoSetup.Color::Red:
           
        BEGIN
             
        CurrForm.Red.VISIBLE:=TRUE; 
             
        CurrForm.Red.XPOS := 0; 
             
        CurrForm.Red.YPOS := 0; 
             
        CurrForm.Red.WIDTH := lintFormWidth; 
             
        CurrForm.Red.HEIGHT := lintFormHeight; 
            
        END;
         
        recDatabaseInfoSetup.Color::Blue: 
            
        BEGIN 
             
        CurrForm.Blue.VISIBLE:=TRUE; 
             
        CurrForm.Blue.XPOS := 0; 
             
        CurrForm.Blue.YPOS := 0; 
             
        CurrForm.Blue.WIDTH := lintFormWidth; 
             
        CurrForm.Blue.HEIGHT := lintFormHeight; 
            
        END; 
            
        //...
            
        //YOU CAN ADD THE REST OF THE COLORS IN THE SAME WAY   
        END;

        //RESIZE FORM
        CurrForm.WIDTH := lintFormWidth;
        CurrForm.HEIGHT := lintFormHeight;

        It all comes down on resizing the form and resizing shapes.

  • I've put the following fields on the form as "useful info":
    • Title: This is a text that you can fill in in the Setup. I suppose you know how to put it in the form Wink.
    • Company: this is the COMPANYNAME statement (Duh...)
    • License Info: To get the license info, you can use the following code

      //recLicense (Record of the table "License Information")
      recLicense.SETRANGE("Line No.",5,6);
      IF recLicense.FIND('-') THEN
       
      REPEAT
         
      IF recLicense.Text <> '' THEN
           
      txtlicense[recLicense."Line No."] :=
              COPYSTR(recLicense.Text, 27, STRLEN(recLicense.Text)-26);
       
      UNTIL recLicense.NEXT = 0;

      With txtlicense[5] and txtLicenseDevil you can find your license information.

    • Number of Sessions: You could be using following code to make it work for SQL and Native databases:

      CLEAR(lrecSession);
      IF lrecSession.RECORDLEVELLOCKING THEN
       
      lrecSession.SETFILTER("Application Name",'@*NAV*');
      intSessionCount := lrecSession.COUNT;

    • User and Database information: You can get this info from the Session Table as well, with this code:

      lrecSession.SETRANGE("My Session", TRUE);
      IF lrecSession.FINDFIRST THEN BEGIN
       
      txtUserID := lrecSession."User ID";
       
      txtDatabaseName := lrecSession."Database Name";
      END
      ELSE BEGIN
       
      txtUserID := '';
        txtDatabaseName := '';
      END;

      This way, you also get the full login (with domain) when logged in with Windows Authentication ... Which I prefer.

Voilà, that's all. Not really "hocus pocus". Just simple and effective.

Hope you like it.

Enjoy!

Posted: 2008-5-1 14:19 by waldo | with 30 comment(s) |
Bookmark and Share

Comments

# Which database are you logged into?

In a conference like Direcionts EMEA , I noticed again how interested people can be in sometimes such

Thursday, May 01, 2008 2:39 PM by waldo

# re: Which database are you logged into?

Do you have a text file of the object that you could share?

Thursday, May 01, 2008 3:57 PM by thaug

# re: Which database are you logged into?

Yes Eric, this is a nice simple and neat solution to a very commonly requested issue.

Thanks for sharing it.

Friday, May 02, 2008 3:44 AM by David Singleton

# re: Which database are you logged into?

I've already sent a link to this blog to customers :)

Friday, May 02, 2008 2:57 PM by DenSter

# re: Which database are you logged into?

:)

o-ow, I hope they like it Wink.

Sunday, May 04, 2008 12:20 PM by waldo

# re: Which database are you logged into?

@thaugh

I have no .txt available.  If you just follow the description, it won't take long, I guess... (I hope).

Sunday, May 04, 2008 1:51 PM by waldo

# re: Which database are you logged into?

Great tip. So simple and yet so useful. It's funny how often the best solutions are the simplest.

Thanks again!

I'll start using it with all my customers from now on!

Monday, May 05, 2008 10:24 PM by Fommo

# re: Which database are you logged into?

Smile

Great!

Tuesday, May 06, 2008 9:21 AM by waldo

# re: Which database are you logged into?

Great tip

Tuesday, May 06, 2008 9:48 PM by Nuno Maia

# re: Which database are you logged into?

The best solutions are simplest - this is really neat and really useful - thanks a lot

Wednesday, May 07, 2008 1:15 AM by James Crowter

# re: Which database are you logged into?

I love this tip and have been playing about with it. I've added a couple of extra features and I'll post something about it when it's done, but I have a question. Is there any way of stopping someone from clicking on the form and pressing ESC which then closes it? Other than setting Close Forms on Esc to No. I tried putting EXIT(FALSE) in the  or putting something in the OnQueryCloseForm() but that is BAAAAD and you can't exit the company or NAV. Any ideas?

Thursday, May 08, 2008 7:13 AM by Gaspode

# re: Which database are you logged into?

Thanks, Guys!

@Gaspode:  I have been strugling with that myself and I don't see a solution (yet).  The only way (for now) is to change the option "Close Forms On Esc" to "No".  

But honestly, we don't do that.

Thursday, May 08, 2008 8:43 AM by waldo

# re: Which database are you logged into?

Hi it's me again. OK so I had a go at doing some things with this idea. If you're interested, take a look at my post on gaspodethewonderdog.blogspot.com/.../where-am-i.html

I did come across a few issues so maybe some of the clever readers of your blog could answer the bits that don't work. Thanks for the inspiration and thanks heaps for posting the idea. Cheers, Dave.

Friday, May 09, 2008 12:21 PM by Gaspode

# re: Which database are you logged into?

Hi,

When I do this, my shapes seem to be on top of the textboxes (so I cannot see the text) - I know I am missing something simple...

Monday, August 11, 2008 5:09 PM by awarnica

# re: Which database are you logged into?

Hi,

You need to add the shapes first - then the labels afterwards, and then the labels will appear on top of the shapes instead of being hidden :)

Monday, August 11, 2008 7:03 PM by awarnica

# re: Which database are you logged into?

Smile

Thanks for posting the answer.  I was going to try this out ... but you were too quickly.

Tuesday, August 12, 2008 8:51 AM by waldo

# re: Which database are you logged into?

Hi,

I have solution which allows to have information form always opened.

Idea is following - form should be allowed to close, because otherwise Navision can't be closed. But when form is closed, Navision timer is activated, which after some time (I use 100 milliseconds) opens the form back and deactivates timer.

I've created single instance codeunit (GeneralInformationMgt) with following code:

OnRun()

CLEAR(NTimer);

CREATE(NTimer);

NTimer.Interval(100);

OpenForm;

FormClosed()

NTimer.Enabled(TRUE);

OpenForm()

NTimer.Enabled(FALSE);

FORM.RUN(FORM::"General Information");

NTimer::Timer(Milliseconds : Integer)

OpenForm;

Here FormClosed and OpenForm are functions with no parameters; NTimer is global variable, Navision Timer automation.

On form's OnCloseForm trigger function GeneralInformationMgt.FormClosed is called.

From codeunit 1 I run GeneralInformationMgt codeunit instead of opening information form.

Hope my explanation is clear enough.

Wednesday, August 13, 2008 5:53 PM by Viktoras

# re: Which database are you logged into?

awarnica, you can use Fromat -> Bring to Front / Send to Back functions on controls.

Wednesday, August 13, 2008 5:57 PM by Viktoras

# re: Which database are you logged into?

That is fantastic Viktoas!

I have implemented your suggestion on my Where Am I tool and it works a treat. I just need to package it up with some instructions and pop it on the downloads page!

Thanks for sharing this and leaving the comment on my blog to let me know you had done it.

Cheers,

Dave.

Thursday, August 14, 2008 3:12 AM by Gaspode

# re: Which database are you logged into?

Hi Waldo,

I've been trying to contact you by various means - I sent an e-mail to your Dynamics User account, I tried an e-mail to question on your MSDynamicsWorld.com article and I tried a private message to your Dynamics User account - all with no luck. This my final last ditch attempt. If you get this could you please send me a private message through this forum?

Thanks, Dave.

Thursday, August 14, 2008 3:45 AM by Gaspode

# re: Which database are you logged into?

Contacted Smile.

Thursday, August 14, 2008 2:10 PM by waldo

# re: Which database are you logged into?

And one tip - you can make it much better and use editbox without borders etc., with BIG font size, and e.g. with character 'g' in 'Webdings' font to fill the background with selected color. Than you can set the FOREGROUND color in OnFormat and you have truecolor background possibility without any big code for each color... ;-)

Monday, August 18, 2008 7:42 AM by Kine

# Where Am I? Now I know! - Gaspode&#39;s Brain Dump

Pingback from  Where Am I? Now I know! - Gaspode&#39;s Brain Dump

Tuesday, October 28, 2008 3:19 PM by Where Am I? Now I know! - Gaspode's Brain Dump

# Overview Waldo's blog 2008

My first full year (January-December)of writing on my blog has passed. When I saw this post on the "NAV

Wednesday, December 24, 2008 10:55 AM by Waldo's Blog <br /> Microsoft Dynamics NAV

# Overview Waldo's blog 2008

My first full year (January-December)of writing on my blog has passed. When I saw this post on the "NAV

Wednesday, December 24, 2008 10:59 AM by Waldo's Blog <br /> Microsoft Dynamics NAV

# Overview Waldo's blog 2008

My first full year (January-December)of writing on my blog has passed. When I saw this post on the "NAV

Thursday, December 25, 2008 2:23 PM by Waldo's Blog <br /> Microsoft Dynamics NAV

# Tip #18 - NAV 2009 RTC - Which database am I logged into

We al know this blog entry of Waldo. It shows you how you can see what database you are logged onto.

Sunday, November 29, 2009 4:13 PM by Mark Brummel

# re: Which database are you logged into?

Works like a charm, really good idea, thanks alot!

Wednesday, January 27, 2010 5:34 PM by Steven

# NAV 2009 R2 System Indicator

As you might have noticed .. in NAV 2009 it was quite difficult to clearly show in which database you

Monday, January 10, 2011 12:52 PM by Waldo's Blog <br /> Microsoft Dynamics NAV

# NAV 2009 R2 System Indicator

As you might have noticed .. in NAV 2009 it was quite difficult to clearly show in which database you

Monday, January 10, 2011 1:53 PM by Waldo's Blog Microsoft Dynamics NAV

Leave a Comment

(required) 
(required) 
(optional)
(required)