# [ ax2012 ] calling Ax32.exe instead of AxHLink.exe

Since AxHLink.exe will limit to only the default configuration, we will call the Ax32.exe that is more open to various configuration instead.

To do that,

AxHLink.exe Dynamics://0?DrillDown_5637192587

we use startupCmd parameter of Ax32.exe

&quot;C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32&quot; &quot;C:\path\to\configuration.axc&quot; -startUpCmd=DrillDown_5637192587

Note that we can find multiple feature of startUpCmd under Switch section of the following class ( as explained in MS ref )

\Classes\SysStartupCmd\Construct

Note2 : allow all arguments to pass from the client is risky, so it is better to call to .bat or .lnk instead of calling directly to ax32.exe

# winCE 5.0 in ARMV4I in a NutShell

– We can use Visual Studio 2005 or 2008 ( up to 2008 only ) in order to develop winCE 5.0 ( or 6.0 ).

– The screen below shown the C# development, in a nutshell

NOTE : BCD.net is the Barcode SDK ( BCD.net.dll ), the other API for winCE i.e. System.Data.SqlClient, or System.Data.SqlServerCe also available.

# How To Connect WinCE device to windows

– To connect Tohken PM250 Barcode Scanner, in Windows 7 (64 bits) we use Windows Mobile Device Center ( Similar to ActiveSync in Windows XP ).

– To solve the Universal serial bus ( USB ) controllers “Unknown Device”, when connecting the PM250 device to the computer, just go to WinCE, Settings > Network and Dial-up Connections, and at USB connection right click and untick ‘Set as Default’.

If this is no help, try unplug and plug USB in many times. There will be some times that windows can install driver. Let’s cross the finger.

# Connect WinCE Device to MSSQL Server

First, I noted that I am using winCE 5.00 with Microsoft SQL Server 2012

Connect to mssql database using IP Address and Port i.e. from the example below connect to port 1234

string connectionString = "Data Source=192.168.2.2,1234;User ID=youruserid;Password=yourpassword;Initial Catalog=yourdatabasename;"

– Before that enable TCP/IP in the SQLSERVER Configuration Manager

SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for SQLEXPRESS

with this configuration, we can also change the port in the ‘IP All’, by replacing ‘TCP Dynamic Ports’ from 0 with ” ( blank ), and set TCP port instead ( in my case 1234 ).

NOTE : when we configure TCP properties, no need to state the instance ( e.g. 192.168.2.2\SQLEXPRESS ), because that particular IP and port has pointed to the instance already.

NOTE  about the connection string, if we connect to SQLEXPRESS instance on the local PC, the connection string can be

Data Source=.\SQLEXPRESS;Initial Catalog=yourdatabasenamenaja;Integrated Security=SSPI

# Problem solved : SQLException : SQL Server does not exist or access denied

– Make sure your Windows firewall is disabled ( or you can configure the windows firewall to allow MSSQL Server, the method is shown below ). Otherwise you will get “SQLException : SQL Server does not exist or access denied” ( Before you will get this message, make sure your print out the SQLException using the below snippet code like in the example here, since “Console.WriteLine(e)” shows no clue. )

try
{
comm.Connection.Open();
}catch (SqlException ex){
StringBuilder errorMessages = new StringBuilder();
for (int i = 0; i &lt; ex.Errors.Count; i++){
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
return;
}

How to configure windows firewall to allow the connection from MSSQL Server

1. go to Windows Firewall

3. Inbound Rules

4. Add program : sqlservr.exe

WARNING : If you have multiple sqlservr.exe in your machine, make sure that you pick the right one. For example, in my case, it is at

C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\sqlservr.exe

NOTE : For me, I didn’t set allow port 1234, and Outbound Rules,

just Inbound rules program point to sqlservr.exe is OK.

# Problem solved : PlatformNotSupportedException

– PlatformNotSupportedException may be occur, if the database codepage is not found in the Regional and Setting of the Device ( something like “PlatformNotSupportedException : at System.Data.SqlClient.TdsParser.GetCodePage(SqlCollation collation)”  error in the stacktrace ). I paste the full error below.

at System.Globalization.CultureInfo..ctor(Int32 culture, Boolean useUserOverride)
at System.Globalization.CultureInfo..ctor(Int32 culture)
at System.Data.SqlClient.TdsParser.GetCodePage(SqlCollation collation)
at System.Data.SqlClient.TdsParser.ProcessEnvChange(Int32 tokenLength)
at System.Data.SqlClient.TdsParser.Run(RunBehavior run, SqlCommand cmdHandler, SqlDataReader dataStream)
at System.Data.SqlClient.TdsParser.Run(RunBehavior run)
at System.Data.SqlClient.SqlInternalConnection..ctor(SqlConnection connection, Hashtable connectionOptions)
at System.Data.SqlClient.SqlConnection.Open()

For example, in my case, my MSSQL database using Thai_CI_AS ( You can know it by using the query “select SERVERPROPERTY(‘Collation’)” ) , but “Thai” Language pack is not installed in the WinCE device ( You can verify whether it is installed in Control Panel > Regional and Language Setting > Your Locale. “Thailand” is not there ).

And the screenshot below shows one way how to solve by changing Database properties in MSSQL Server management Studio. Change the Collation of the database to whatever your winCE support.

NOTE : you can see the description of each Collation from executing SQL Query “select * from fn_helpcollations();” and this is ref)

# Problem solved : SQLException : General network error. Check your network documentation.

When I try “cmd.ExecuteReader()” from winCE 5.0, to fetch the data from the MSSQL 2012 Server, I face “SQLException, General network error”.

I try to look at the query log using “SQL Server Profiler” program, which show the connection coming from “.Net SqlClient Data Provider”. First it starts with “Audit Login”, then follow with “RPC:Completed” ( which execute the function like “exec sp_executesql N’SELECT …'”), then “Audit Logout” when the system throws the error.

It have no problem with command.ExecuteNonQuery() the system can update the record in the database, only when I query using the comm.ExecuteReader() that has the problem.

Solution :

There is a lot of the solution on the internet regarding “General Network Error”, since microsoft randomly thrown this error to the one which is not related with the Network at all. I try a lot of solution from the internet, but it does not help in my case, til I found this article. The article suggest me to use the query that query from the information_schema view instead. The query is below.

SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

and it works ! Therefore, something is wrong with my table.

After inspect my table, the problem is found

When we create new column in MSSQL 2012, the default datatype that popup is nchar(10) ( like column xxx in the picture above ). However, this causes the “General Network Error” ( WTF ! ). The solution is change it to use other datatype, i.e. int, or nvarchar() instead.

OK now ! FINALLY !!!!