How to use jQuery getJSON in ASP.NET MVC

In order to populate a dropdown control based on selection of another one, I used this code:

on controller I create the method below:

than on the view I used jQuery:

MS SQL How To Store a File into a blob field

If you need to store a file from your hard drive into a filed in MS Sql Server, you can run this code


How To Returning JSON from a .Net 4.0 WebService

I lose a lot of time to understand why my web service didn’t return me a JSON but an XML instead.
After many searches if find the answer and I want to share it.

With Framework 4.0 when you specify this:

1:  [WebMethod]  
2: [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
It isn’t enough for retrieve a JSON answer.
In order to retrieve a JSON you must use this code:
1:  Context.Response.Write(serializer.Serialize(jsonData));   

So an example of a WebMethod will be:

1:  [WebMethod]  
2: [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
3: public void MyWebMethod()
4: {
5: try
6: {
7: var retval = JsonConvert.SerializeObject(new MyObject());
8: Context.Response.Write(retval);
9: }
10: catch (Exception ex)
11: {
12: Context.Response.Write(string.Format("[ERROR: {0}]", ex.Message));
13: }
14: }

How to use jQuery and Footable to make GridView responsive

Nowadays make a website compatible with desktop platforms and mobile is a must.
Making a responsive design is important to adapt the content of your website to the platform where it will be viewed.
To render the GridView control responsive we procdeed to hide some columns with Footable and jQuery plugins.
In order to do that, download Footable plugin
Now in your aspx page add the follow code:

Add a GridView control, this is the ASP.NET code for that:

Initialize footable plugin to the GridView control

Populate the GridView with data

The default header row for GridView is now generated, now we need to make it accessible

So we can proceed to define which colums will be hided in which devices

You can teel to Footable which columns to hide on which breakpoints, by specifying data-hide attributes on the table head columns

Microsoft SQL LocalDB

LocalDB was introduced in SQL Server 2012 CTP3. It’s basically a new version of SQL Express, with same functionality, dedicated to developers. So you don’t need to install any SQL server. If you have installed SQL 2012 or Visual Studio 11 then you already have it, and it runs over .Net 4 or higher. If you are using Visual Studio 11 and have been playing with the new EntityFramework and MVC, you can see it on the default connection string.
When you start a debug session the LocalDB starts on a different process with a clean instance of SQL. When you stop the debug session, it stops. And this is quite fun sinceyou get a full local dedicated database per debug session started and stopes by VS. The LocalDB also support Database as a file during the connection process letting the developers work on local MDF/LDF file.
  1. LocalDB uses the same sqlservr.exe as the regular SQL Express and other editions of SQL Server. The application is using the same client-side providers (ADO.NET, ODBC, PDO and others) to connect to it and operates on data using the same T-SQL language as provided by SQL Express.
  2. LocalDB is installed once on a machine (per major SQL Server version). Multiple applications can start multiple LocalDB processes, but they are all started from the same sqlservr.exe executable file from the same disk location.
  3. LocalDB doesn’t create any database services; LocalDB processes are started and stopped automatically when needed. The application is just connecting to “Data Source=(localdb)v11.0″ and LocalDB process is started as a child process of the application. A few minutes after the last connection to this process is closed the process shuts down.
  4. LocalDB connections support AttachDbFileName property, which allows developers to specify a database file location. LocalDB will attach the specified database file and the connection will be made to it.
If you have an instance of SQL Server 2008 or Visual Studio 2010 than you cannot connect to this database. You can only connect using SQL 2012 or VS 11

You can download LocalDB from this page. And as I mentioned above – get the full functionality of SQL Express (Linq, XML, ADO .Net, Spatial Types, SP, T-SQL). It will only work with local connections, does not run on mobile devices and the DB size is limited to 10GB (1 CPU).

How to Rename SQL Server

In case of server migrations or if you are in a situation to rename the physical server hosting SQL Server, Renaming SQL Server to host the new physical server name is pretty simple as done below

MSDN Reference for Add Server

This procedure must be executed on all instances of the Database Engine hosted on the computer but the instance name of the Database Engine cannot be changed. On the SQL Server instance, run the following query:

sp_dropserver ‘<oldservername>’

sp_addserver ‘<newservername>’, local

Now restart the SQL Server related services. Then, the command below to verify if the new name has been updated.

select @@servername

AX2012 SSRS Unable to log on to Microsoft Dynamics AX

When you run any Report and the system returns the error:

Unable to log on to Microsoft Dynamics AX

The solution, that works for me, is to run the Reporting Services with the same user used for runing the AOS

AX2012 R2: Failed to create a session

I retrive in AX2012 R2 the foolowing error when I sync the DB or when I try to load a queque of batch jobs:

Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft Dynamics

A closer look into this learned that this is linked to the new partitions feature.

It seems the UserInfo table is not correctly updated and the partition administrator is not updated correctly when you restore an existing DB or the Demo database.
To fix this, you can do the following.

Stop the AOS
Restore the database again
Start the AOS
Start a client and complete the partition initialiasation checklist
Close the client and execute the script below on the SQL database
Restart the client and reimport your license (if you were restoring the Microsoft demo data, the demo license is back in there)
Then compile / generate CIL / DB sync and you should be on track again!
The script for updating the UserInfo inforation is as follows:

How to create a custom Dialog with AX 2012

Microsoft Dynamics AX 2012 R3: a preview

It’s all about Amazing Customer Experiences
Over the past few years Microsoft Dynamics AX has evolved to be the default enterprise resource planning (ERP) choice for many organizations. Our focus on innovation and business value to our customers has grown our Microsoft Dynamics AX community to more than 20,000 customers across more than 36 countries. That makes us happy.
Now, we’re so excited to be unveiling Microsoft Dynamics AX 2012 R3, planned for release in April 2014. And you know why? Because we know it will help you to provide Amazing Customer Experiences! With new features and tools available through this release, you’ll be able to engage with customers on their terms, run agile operations to exceed your customers’ needs, and expand your business to better serve your customers.
Engage with customers on their terms
Customers are increasingly demanding a seamless shopping experience across channels and an unprecedented degree of interaction with – or ‘ownership’ of – consumer brands. Mobile experiences delivered through Microsoft Dynamics AX 2012 R3 provide differentiating customer-facing experiences that help you:
  • Engage anytime, anywhere. Online, in store or on-the-go, customers want business on their own terms. With the next release, you can get tools to create seamless omni-channel engagements, with the ability to handle multiple languages and storefronts.
  • Offer deeply engaging, rich experiences. We’re closing the gap between the systems that capture the data and the people who can use it to benefit customers. You’ll be able to provide more meaningful services and advice to your customers in a way that makes sense for them.
  • Build profitable customer relationships. New social channels integration and ecommerce new features in Microsoft Dynamics AX 2012 R3 let teams work together to serve customers in new ways, including support for customer-specific pricing, wish lists, and unassisted sales. Get support for loyalty programs across legal-entities and tiering of customers as well as enhanced gift card functionality. Even incorporate Facebook and Twitter into campaigns right out of the box.
Satisfy changing customer needs
We know you want to respond to fast-changing business conditions and move quickly to capitalize on new opportunities. Look to Microsoft Dynamics AX 2012 R3 to help you streamline your business and make customers happy:
  • Offer choices. New and integrated Warehouse and Transportation Management capabilities helps you provide your customers with the fulfillment choices they want. You can even quickly act on their changing requirements with a few clicks of a button—and still keep logistics and transportation costs low.
  • Respond to continuously shifting customer requirements. Timely, end-to-end visibility into supply chain operations helps you balance inventory and operating expenses. In addition, we now provide support for basic SKU-level demand forecasting based on historic data, using a combination of Microsoft SQL Server and Microsoft Excel to view, visualize, and edit the forecast data.
  • Share highly-responsive, timely delivery insights with customers. With the integrated warehousing and transportation capabilities you have insight into your global supply chain with a few clicks, and can share this insight with your customers since they value information about their order status as much as receiving the order.
Serve your customers better and expand your business
Grow into new markets and new customer segments. Blend in new acquisitions and new lines of business without sacrificing enterprise-wide visibility and process controls. Microsoft Dynamics AX 2012 R3 can help reach new customers in new ways:
  • Deliver solutions to new geographies. Single-instance solutions help deploy organizational best practices to new geographies quickly and easily—without starting from scratch. The planned Master Data Management capabilities also support decentralized global installations. Manage Microsoft Dynamics AX projects from pre-sales to implementation and operations Lifecycle Services, a cloud-based framework that makes it easier to grow.
  • Innovate products and services. With Microsoft Dynamics AX 2012 R3, you and your employees have the insight and flexibility to drive innovation that improves business operations and the way they serve customers—empowering you to give customers what they want, when they want it.