Tuesday, March 19, 2019

Enable SQL Server Remote Connections

About this task
Microsoft SQL Server is a relational database management system (RDBMS) produced by Microsoft. Its primary query language is Transact-SQL, an implementation of the ANSI/ISO standard Structured Query Language (SQL) which is used by Microsoft. You need to allow distant users to connect to the SQL server so they can address it their queries.
SQL Server is used by:
  • Content Manager End User components;
  • Content Manager Author components;
  • Content Manager Database.
Note: The first step of this procedure is sufficient in most cases. Go through the other steps if you encounter any issue.

Procedure


  1. Enable remote connections to your SQL Server.
    1. Open SQL Server Management Studio.
    2. Right-click your server's name and select Properties.
    3. Tick the checkbox Allow remote connections to this server.
    4. Select OK.
    Microsoft SQL Server by default uses TCP 1433 but this can be changed using SQL Server Enterprise Manager or the database Management Studio.
  2. Enable TCP/IP.
    1. Open the SQL Server Configuration Manager.
    2. In SQL Server Network Configuration select Protocols for [yourServerInstance].
    3. In the right-hand pane, make sure that TCP/IP is Enabled.
  3. Open the 1433 port in your firewall.
    1. In the SQL Server Configuration Manager, right-click TCP/IP and select Properties.
    2. Select the IP Addresses tab and make sure the TCP Port for IP1 is 1433.
  4. If you are using a named instance, create an extra rule in your firewall with the port 1434.
    Note: For a named SQL Server instance (e.g. [yourServerInstance]\SQL2012SP2), the firewall needs an extra rule on the UDP protocol with the specific port 1434. Without this rule the system will return the exception error: 26 - Error Locating Server/Instance Specified.
    1. Display the firewall advanced settings by navigating to Control Panel > System and Security > Windows Firewall > Advanced settings.
    2. Select Inbound Rules in the left-hand pane, then click New Rule in the right-hand pane.
    3. In the New Inbound Rule WizardRule Type step, select Port.
    4. Protocols and Ports step, select UDP and set Specific local ports to 1434.
    5. Action step, select Allow the connection.
    6. Profile step, tick the Domain checkbox.
    7. Name step, enter a name for this rule, e.g. Named instance port 1434.
    8. Select Finish.

Thursday, November 8, 2018

Simple AngularJS application with ASP.NET MVC

In this example i'm gonna show you how to return a simple data set in from ASP.NET MVC server side and bind the view using Angular directives.

First, let see how our controller looks like on the server side.

public class StudentController : Controller
{
    // GET: Student
    public ActionResult Index()
    {
        return View();
    }

    public JsonResult GetAllStudents()
    {
        return Json(GetStudents(), JsonRequestBehavior.AllowGet);
    }

    private List<Student> GetStudents()
    {
        List<Student> students = new List<Student>()
        {
            new Student()
            {
                Name = "Chamara",
                School = "Melbourne"
            },
            new Student()
            {
                Name = "Layana",
                School = "Bayswater"
            }
        };

        return students;
    }
}

public class Student
{
    public string Name { get; set; }
    public string School { get; set; }
}

Then the Student.js file which holds the Angular js code.

var StudentApp = angular.module('StudentApp', []);


StudentApp.factory("StudentService", ['$http', function ($http) {

    var StudentService = {};
    StudentService.getStudents = function () {

        return $http.get("/Student/GetAllStudents");

    };

    return StudentService;

}]);

StudentApp.controller("StudentController", function ($scope, StudentService) {

    getStudents();
    function getStudents() {

        StudentService.getStudents().then(function (studs) {

            $scope.students = studs;
            console.log($scope.students);

        });

    }

});
Finally, binding the view.

<script src="~/Scripts/app/StudentApp.js"></script>

<h2>Students</h2>

<div ng-app="StudentApp">
    <div ng-controller="StudentController">       
        <table>
            <tr ng-repeat="r in students.data">
                <td>{{r.Name}}</td>
                <td>{{r.School}}</td>
            </tr>
        </table>
    </div>
</div>