DAXSPOT

Wednesday, October 19, 2022

How to drop SQL Server database currently in use and in Single user mode, MS SQL.

Hi All,


Working in MS SQL, you must have faced below error at least once. 


Issue: How to drop SQL Server database currently in use and in Single user mode.


Error:

"changes to the state or options of database 'AxDB' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it."


Solution:

This built-in stored procedure shows all connections to a database

exec sp_who2


And this query kills a connection to the database, for example connection SPID #53

kill 53


Thank you!

Tuesday, October 18, 2022

Avoiding "Divided by zero" error, X++

Hi,


Two ways to avoid the error "Divided by Zero".


int    a,b,c;

a = 2;

b = 0;

if(b)

    c = a / b;

else

    print "Cannot divide by zero"

//Output is "Cannot divide by zero" because "b" is zero so else statement will run.


(OR)


c  = a / minOne(b); 

//Output is C = 2, reason given below.


Function minOne() returns non zero values. If "b" is zero then it returns one.


Thank you,


Tuesday, October 11, 2022

Add or Minus Days in DateTime or Date Datatype, X++

Hi,

below you will find ways to add/minus days in "DateTime" or "Date" Datatype.


Example 1: Days add/minus in "DateTime" Datatype.

{

 utcDateTime         todayLessOneDay;

// Get the actual UTCDateTime based on the current system

todaysDateTime = DateTimeUtil::utcNow();

// Convert it to a string, just to show in on the info log

info(DateTimeUtil::toStr(todaysDateTime));

// Now less a day

todayLessOneDay = DateTimeUtil::addDays(todaysDateTime, -1);

// And Info it out again

info(DateTimeUtil::toStr(todayLessOneDay));

}


Example 2: Days add/minus in "Date" Datatype.

{

  TransDate transDate = today();

  ;

  transDate++;

  print transDate - 2;

  pause;

}

Sunday, October 9, 2022

Add multiple Query Value to one Query Range - X++

 Hello,

In this post you will find a code sample to run multiple Query Value to one Query Range.


You have two options:


Option 1: Add multiple ranges.

QueryBuildDataSource qbds = q.dataSourceTable(BOMTable);

QueryBuildRange qbr;

while (...)

{

    qbr = qbds.addRange(fieldNum(BOMTable, BOMId));

    qbr.value(queryValue(BOMVersion.BOMId));

}


Option 2: Add multiple values to one range separated by comma.

QueryBuildRange qbr = q.dataSourceTable(BOMTable).addRange(fieldNum(BOMTable, BOMId));

container c;

while (...)

{

    c+= queryValue(BOMVersion.BOMId);

}

qbr.value(con2str(c));

How to execute SQL directly form Dynamics AX X++

How to execute Sql directly form Dynamics AX X++ Reference by : alirazazaidi Dynamics Ax provide many other ways to communicate with databas...