[ ax2012 ] called by Csharp

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
// System.Diagnostics.Process process = new System.Diagnostics.Process();
// System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
// startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
// startInfo.FileName = "cmd.exe";
// startInfo.Arguments = "C:/Program Files (x86)/Microsoft Dynamics AX/60/Client/Bin/Ax32.exe";
// process.StartInfo = startInfo;
// process.Start();

string str = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = str;
process.StartInfo.Arguments = @"-startupcmd=AutoRun_C:\csharp_prototype\XMLFile1.xml";
process.Start();

}

private void button2_Click(object sender, RoutedEventArgs e)
{
string str = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = str;
process.StartInfo.Arguments = @"-startupcmd=AutoRun_C:\csharp_prototype\XMLFile2.xml";
process.Start();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>

<AxaptaAutoRun logFile="$HOME\axEXProd.log" version="4.0" exitWhenDone="false">

<Run name="SalesTableListPage" type="displayMenuItem"/>

</AxaptaAutoRun>

more info : http://msdn.microsoft.com/en-us/library/sysautorun.aspx

Advertisements

[ C# ] Provider=OraOLEDB.Oracle Connection Pool

From oracle site that link to MS site,

Default services enabled DBPROP_INIT_OLEDBSERVICES

property value

All services (default) DBPROPVAL_OS_ENABLEALL
All except pooling and automatic transaction enlistment (DBPROPVAL_OS_ENABLEALL & ~DBPROPVAL_OS_TXNENLISTMENT & ~DBPROPVAL_OS_RESOURCEPOOLING)
All except pooling (DBPROPVAL_OS_ENABLEALL &

~DBPROPVAL_OS_RESOURCEPOOLING)

All except automatic transaction enlistment (DBPROPVAL_OS_ENABLEALL &

~DBPROPVAL_OS_TXNENLISTMENT)

All except Client Cursor Engine (DBPROPVAL_OS_ENABLEALL & ~DBPROPVAL_OS_CLIENTCURSOR)
All except pooling, automatic transaction enlistment, and Client Cursor Engine (DBPROPVAL_OS_ENABLEALL & ~DBPROPVAL_OS_RESOURCEPOOLING & ~DBPROPVAL_OS_TXNENLISTMENT & ~DBPROPVAL_OS_CLIENTCURSOR)
Pooling and automatic transaction enlistment only, session level aggregation only DBPROPVAL_OS_TXNENLISTMENT & DBPROPVAL_OS_RESOURCEPOOLING
No services DBPROPVAL_OS_DISABLEALL
Default services enabled Value in connection string
All services (default) “OLE DB Services = -1;”
All except pooling and automatic transaction enlistment “OLE DB Services = -4;”
All except Client Cursor Engine “OLE DB Services = -5;”
All except pooling, automatic transaction enlistment, and Client Cursor Engine “OLE DB Services = -8;”
Pooling and automatic transaction enlistment only, session level aggregation only “OLE DB Services = 3;”
No services “OLE DB Services = 0;”

We noticed that Oracle pooling is enabled by default.

Quote from Oracle site, “By default, the OLEDB_SERVICES registry entry for OraOLEDB is set, under the CLSID of OraOLEDB, to 0xffffffff (that is, -1), which enables all services. Certain OLE DB Services can also be disabled or enabled programmatically through the DBPROP_INIT_OLEDBSERVICES property setting.”

[ C#] MVC 2 101

Create New Project

In visual studio, File > New Project
`Visual C# Projects` and in the Templates pane, select `ASP.NET MVC 2 Web Application`.

The files will be generated.

SFA.sln
SFA\App_Data
SFA\bin
SFA\Content\Site.css
SFA\Controllers\AccountController.cs
SFA\Controllers\HomeController.cs
SFA\Global.asax
SFA\Global.asax.cs
SFA\Models\AccountModels.cs
SFA\obj\Debug
SFA\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
SFA\obj\Debug\Package
SFA\obj\Debug\TempPE
SFA\Properties\AssemblyInfo.cs
SFA\Scripts\jquery-1.4.1-vsdoc.js
SFA\Scripts\jquery-1.4.1.js
SFA\Scripts\jquery-1.4.1.min.js
SFA\Scripts\jquery.validate-vsdoc.js
SFA\Scripts\jquery.validate.js
SFA\Scripts\jquery.validate.min.js
SFA\Scripts\MicrosoftAjax.debug.js
SFA\Scripts\MicrosoftAjax.js
SFA\Scripts\MicrosoftMvcAjax.debug.js
SFA\Scripts\MicrosoftMvcAjax.js
SFA\Scripts\MicrosoftMvcValidation.debug.js
SFA\Scripts\MicrosoftMvcValidation.js
SFA\SFA.csproj
SFA\SFA.csproj.user
SFA\SFA.Publish.xml
SFA\Views\Account
SFA\Views\Home
SFA\Views\Shared
SFA\Views\Web.config
SFA\Views\Account\ChangePassword.aspx
SFA\Views\Account\ChangePasswordSuccess.aspx
SFA\Views\Account\LogOn.aspx
SFA\Views\Account\Register.aspx
SFA\Views\Home\About.aspx
SFA\Views\Home\Index.aspx
SFA\Views\Shared\Error.aspx
SFA\Views\Shared\LogOnUserControl.ascx
SFA\Views\Shared\Site.Master
SFA\Web.config
SFA\Web.Debug.config
SFA\Web.Release.config
----------------------------------------------------------------- UnitTest
SFA.Tests\App.config
SFA.Tests\bin
SFA.Tests\Controllers
SFA.Tests\obj
SFA.Tests\Properties
SFA.Tests\SFA.Tests.csproj
SFA.Tests\bin\Debug
SFA.Tests\Controllers\AccountControllerTest.cs
SFA.Tests\Controllers\HomeControllerTest.cs
SFA.Tests\obj\Debug
SFA.Tests\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
SFA.Tests\obj\Debug\TempPE
SFA.Tests\Properties\AssemblyInfo.cs

Build and Deploy

In Solution Manager, Right Click at the project > Build

Click `Start Debugging (F5)` icon

The default route

Global.asax.cs

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

i.e. http://localhost:52386/Home/About calls method About()

in SFA\Controllers\HomeController.cs

 

Passing The data from controller to view

Controller

ViewData["Message"] = "Welcome to ASP.NET MVC!";

View

<%: ViewData["Message"] %>

Action Anchor

View

<%: Html.ActionLink("Register", "Register") %>

Form

View : Account/LogOn.aspx

NOTE : submit to Account/LogOn.aspx

<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %>
<div>
<fieldset>
<legend>Account Information</legend>

<div>
<%: Html.LabelFor(m => m.UserName) %>
</div>
<div>
<%: Html.TextBoxFor(m => m.UserName) %>
<%: Html.ValidationMessageFor(m => m.UserName) %>
</div>

<div>
<%: Html.LabelFor(m => m.Password) %>
</div>
<div>
<%: Html.PasswordFor(m => m.Password) %>
<%: Html.ValidationMessageFor(m => m.Password) %>
</div>

<div>
<%: Html.CheckBoxFor(m => m.RememberMe) %>
<%: Html.LabelFor(m => m.RememberMe) %>
</div>

<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
<% } %>

Model : AccountModels.cs

#region Models

public class LogOnModel
{
[Required]
[DisplayName("User name")]
public string UserName { get; set; }

[Required]
[DataType(DataType.Password)]
[DisplayName("Password")]
public string Password { get; set; }

[DisplayName("Remember me?")]
public bool RememberMe { get; set; }
}

#endregion

Properties Message

Web.config

i.e. minRequiredPasswordLength

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>

 

 

[ C# ] create web project 101

New Project

In visual studio, File > New Project

`Visual C# Projects` and in the Templates pane, select `ASP.NET Web Application`.

The source will be generated,

About.aspx           #
About.aspx.cs
About.aspx.designer.cs
Account\ChangePassword.aspx
Account\ChangePassword.aspx.cs
Account\ChangePassword.aspx.designer.cs
Account\ChangePasswordSuccess.aspx
Account\ChangePasswordSuccess.aspx.cs
Account\ChangePasswordSuccess.aspx.designer.cs
Account\Login.aspx                     #
Account\Login.aspx.cs
Account\Login.aspx.designer.cs
Account\Register.aspx                #
Account\Register.aspx.cs
Account\Register.aspx.designer.cs
Account\Web.config
App_Data
bin
Default.aspx                          #
Default.aspx.cs
Default.aspx.designer.cs
Global.asax
Global.asax.cs
obj\Debug
obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
obj\Debug\TempPE
Properties\AssemblyInfo.cs
Scripts\jquery-1.4.1-vsdoc.js
Scripts\jquery-1.4.1.js
Scripts\jquery-1.4.1.min.js
SFA.csproj
SFA.csproj.user
Site.Master
Site.Master.cs
Site.Master.designer.cs
Styles\Site.css
Web.config
Web.Debug.config
Web.Release.config

Build and Deploy

In Solution Manager, Right Click at the project > Build

In Solution Manager, Right Click at the project > View in Browser

Add New Page

right click project > Add > New Item

.. Web Form

The files will be generated.

PongTest.aspx – the visual representation
PongTest.aspx.cs or PongTest.aspx.vb – Code for event handling

PongTest.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PongTest.aspx.cs" Inherits="SFA.PongTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

 PongTest.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SFA
{
public partial class PongTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

ref : microsoft

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. winCE_connection_remove_set_as_default_to_connect_to_windows_7_x64

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 ).

TCP_IP_properties_for_SQLEXPRESS

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

2. Advanced settings

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.Login(Int32 timeout)
at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()
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)

how_to_change_codepage_mssqlserverProblem 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

general_network_error_mssql_2012When 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 !!!!