Database File Group selection for keys

I sure would like to be able to split large Dynamics NAV databases into multiple file groups that reside on separated disks.  I suggest that the available file groups can be selected for each key in the table designer.

Please vote here if you would also like this possibility.

 

Batch Job to Quit if it is blocking

I have a batch job that is running regularly to adjust items.  Since this is running during working hours I want to stop the batch if it is blocking another user. This is the loop that my batch does.
[code htmlscript=”false”]FOR i := 1 TO 50 DO BEGIN
IF AmILocking(LockingForUserID) THEN BEGIN
COMMIT;
ERROR(Text001,LockingForUserID);
END;
AdjustItems;
END;[/code]
Text001 is “Locking for user id %1, quitting !” and AmILocking function is
[code htmlscript=”false”]AmILocking(VAR LockingForUserID : Text[30]) Locking : Boolean
Session.SETRANGE(Blocked,TRUE);
Locking := Session.FINDFIRST;
LockingForUserID := Session."User ID";[/code]
where Session is the virtual table Session as a local variable.

Find current Server and Database Name

Here are my way of finding the current database server and database name for both Classic Client and RTC Client.
[code htmlscript=”false”]IF ISSERVICETIER THEN BEGIN

IF ISCLEAR(DomDoc) THEN
CREATE(DomDoc);

DomDoc.load(APPLICATIONPATH + ‘CustomSettings.config’);
DomNode :=
DomDoc.selectSingleNode(
‘//appSettings/add[@key=”DatabaseServer”]’);
MyServerName := DomNode.attributes.item(1).text;

DomNode :=
DomDoc.selectSingleNode(
‘//appSettings/add[@key=”DatabaseName”]’);
MyDatabaseName := DomNode.attributes.item(1).text;

END ELSE BEGIN
MyServer.SETRANGE("My Server",TRUE);
MyServer.FINDFIRST;
MyServerName := MyServer."Server Name";

MyDatabase.SETRANGE("My Database",TRUE);
MyDatabase.FINDFIRST;
MyDatabaseName := MyDatabase."Database Name";
END;[/code]
The Global Variables are

Name DataType Subtype Length
DomDoc Automation ‘Microsoft XML, v6.0’.DOMDocument
DomNode Automation ‘Microsoft XML, v6.0’.IXMLDOMNode
MyServerName Text 50
MyDatabaseName Text 50

Loading a client file into BLOB with RTC Client

For some time have been looking for a solution on how to upload a file into BLOB with RTC Client.  The built in functions, UPLOAD and UPLOADINTOSTREAM both force an Open Dialog unless you first copy the file to a temporary path.  I already had the file name and wanted to skip that part.

I always stopped on the fact that I was unable to move binary data with code from the client layer to the server layer.  Then today, I finally got an idea on how to solve this.  I convert the client file to a base64 string, transfer that string to the server layer and save as a file.  Then I create a binary server file based on the base64 server file.  That file is identical to the client file and ready to be imported into BLOB on the server side.
[code htmlscript=”false”]IF ISSERVICETIER THEN BEGIN
Document.ADDTEXT(
ClientConvert.ToBase64String(
ClientFile.ReadAllBytes(ImageFileName)));
ServerBase64FileName := ThreeTireMgt.ServerTempFileName(”,”);
ServerFileStream.WRITEMODE(TRUE);
ServerFileStream.CREATE(ServerBase64FileName);
ServerFileStream.CREATEOUTSTREAM(OutStr);
Document.WRITE(OutStr);
ServerFileStream.CLOSE;

ServerDocumentFileName := ThreeTireMgt.ServerTempFileName(”,”);
ServerDocumentFile.WriteAllBytes(
ServerDocumentFileName,
ServerConvert.FromBase64String(
ServerBase64File.ReadAllText(ServerBase64FileName)));

ServerFileStream.OPEN(ServerDocumentFileName);
ServerFileStream.CREATEINSTREAM(InStr);
Image.CREATEOUTSTREAM(OutStr);
COPYSTREAM(OutStr,InStr);
ServerFileStream.CLOSE;
ServerBase64File.Delete(ServerBase64FileName);
ServerDocumentFile.Delete(ServerDocumentFileName);
END ELSE BEGIN
Image.IMPORT(ImageFileName,FALSE);
END;[/code]
This should support files upto 1.5GB in size.

ImageTest

Blocking Log

Today I needed to see who was blocking another user and why.  I created a few objects to monitor the Session table and log the information.

I use ADO to connect to the database server to get the current SQL statement for each session to be able to see what is beeing locked.

Objects attached.

Blocking Log