Wednesday 16 December 2015

SQL CDC Error

When trying to enable the CDC on SQL database, the following error message displays:
  • Could not update the metadata that indicates database is enabled for Change Data Capture. The failure occurred when executing the command SetCDCTracked (Value = 1)

This error message comes when trying to enable CDC on a SQL Server 2008 database when the owner is not "sa".The fix for this is to change the database owner to "sa" by executing the below script:
  • USE <database-name>
  • GO
  • EXEC sp_changedbowner 'sa'



Friday 20 November 2015

Find SQL fast in SQL Server Management Studio

  • Find fragments of SQL in tables, views, stored procedures, functions, views, jobs, and more
  • Quickly navigate to objects wherever they happen to be on a server
  • Search across multiple object types and multiple databases
  • Find all references to an object
  • Search with booleans and wildcards

SQL Search is a free add-in for SQL Server Management Studio that lets you quickly search for SQL across your databases more...

 

Monday 9 November 2015

Implementing Active Directory Change Notifications in .NET

There are three ways of figuring out things that have changed in Active Directory (or ADAM)  more...
How to poll for changes to the Active Directory by using Visual C#  more...

 

Enabling Create System Image in Windows 7, 8 and 8.1

When trying to make image of disk in Windows, it says:
Windows backup: This feature has been disabled by your system administrator. Contact your administrator for access.

more...

Wednesday 4 November 2015

Setup IIS 7 AppPool Identities as SQL Server Logons

C# application can access SQL Database and fetch the data when it runs in IIS Express but cannot connect to SQL Database when runs in IIS. To solve the problem, IIS APPPOOL\AppPoolName must be created and have control over the desired database. To do this:
  • In SQL Server Management Studio, look for the Security folder (the security folder at the same level as the Databases, Server Objects, etc. folders...not the security folder within each individual database)
  • Right click logins and select "New Login"
  • In the Login name field, type IIS APPPOOL\AppPoolName - do not click search
  • Fill whatever other values you like (i.e., authentication type, default database, etc.)
  • Click OK

'AppPoolName' can be fine by:
  • Select the desire website in IIS
  • Click on Basic Bindings
  • Application Pool Name will be the values of the 'Application Pool' 



    Monday 2 November 2015

    Random Number Generator to Generate Different Numbers

    C# Random method is initialized using the clock. That's why it generates same value every time it calls. Here is the solution to generates different numbers:


    private static readonly Random random = new Random();
    private static readonly object syncLock = new object();

    public static int RandomNumber(int min, int max)
    {
        // synchronize
        lock (syncLock)
        {
            return random.Next(min, max);
        }
    }


    Tuesday 20 October 2015

    ASP.NET MVC WebGrid Helper

    ASP.NET MVC - Get the data from database and display as sort-able grid:

    .cshtml page
    @{
        var db = Database.Open("tutorial");   // db connection string
        var selectQueryString = "SELECT * FROM students ORDER BY id";   // sort by id by default
        var data = db.Query(selectQueryString);
        var grid = new WebGrid(data);
    }

    <div id="grid">
        @grid.GetHtml()
    </div>


    Web config database connection string:
    <add name="tutorial" connectionString="Data Source=localhost;Initial Catalog=students;Integrated Security=true;" providerName="System.Data.SqlClient"/>


    Tuesday 6 October 2015

    Windows Service Start Failure

    After adding the custom service to Windows service list, the service starts but after few seconds, it stops working.

    Solution: Application MUST use the Release build rather than debug build.


    Tuesday 29 September 2015

    Partial-Page Rendering

    Partial-page rendering removes the need for the whole page to be refreshed during postback. To do this, put the components under ContentTemplate as follow:


    <asp:UpdatePanel ID="updatePanel" runat="server">
        <ContentTemplate>
            .
            .
            .      
        </ContentTemplate>
    </asp:UpdatePanel>


    Tuesday 7 July 2015

    Get SQL Data using PHP and Display using HTML

    getSqlData.php

    <?php
        header("Access-Control-Allow-Origin: *");
        header("Content-Type: application/json; charset=UTF-8");

        $conn = new mysqli("localhost", "root", "root", "World");
        $result = $conn->query("SELECT Code, Name, Region FROM Country");

        $outp = "[";
        while($rs = $result->fetch_array(MYSQLI_ASSOC))
        {
            if ($outp != "[")
                $outp .= ",";
           
            $outp .= '{"Code":"'. $rs["Code"] . '",';
            $outp .= '"Name":"' . $rs["Name"] . '",';
            $outp .= '"Region":"' . $rs["Region"] . '"}';
        }
        $outp .="]";

        $conn->close();
        echo($outp);
    ?>



    index.html
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title></title>
        </head>
        <body>
            <div id="id01"></div>
            <script>
                var xmlhttp = new XMLHttpRequest();
                var url = "http://localhost/SampleWebSite/getSqlData.php";
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        myFunction(xmlhttp.responseText);
                       
                }
                xmlhttp.open("GET", url, true);
                xmlhttp.send();
                function myFunction(response)
                {
                    var arr = JSON.parse(response);
                    var i;
                    var out = "<table>";
                    for(i = 0; i < arr.length; i++)
                    {
                        out += "<tr>"+
                                    "<td>" + arr[i].Code + "</td>" +
                                    "<td>" + arr[i].Name + "</td>" +
                                    "<td>" + arr[i].Region + "</td>"+
                                "</tr>";
                    }
                    out += "</table>";
                    document.getElementById("id01").innerHTML = out;
                }
            </script>
        </body>
    </html>



    Sunday 5 July 2015

    No 'Access-Control-Allow-Origin' Header is Present on the Requested Resource

    Add the following headers to the HTML file:

    <!DOCTYPE html>
    <html>
       <head>

          <?php
              header('Access-Control-Allow-Origin: *');
              header('Access-Control-Allow-Methods: GET, POST');
          ?>
    .
    .
    .



    Call PHP Method with Parameter from HTML

     <?php
         if (isset($_POST['getData']) and isset($_POST['country']))
         {       
            $servername = "localhost";
            $username = "root";
            $password = "root";
            $dbname = "World";

            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);

            // Check connection
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            }
            $sql = "SELECT code, name FROM country where name='" .  $_POST['country'] . "';";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo $row["code"]. " - " . $row["name"]. "<br>";
                }
            } else {
                echo "0 results";
            }
            $conn->close();
        }
    ?>


    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title></title>
        </head>
        <body>

           <form action="" method="post">
               Country: <input type="text" name="country">
               <input type="submit" name ="getData" value="send"></input>
            </form>

        </body>
    </html>

    Tuesday 23 June 2015

    Receive Yahoo Emails in Outlook 2013 using IMAP

    1. File > Add Account
    2. Manual setup or additional server types > Next
    3. IMAP > Next
    4. Account Settings:
      • Your Name: name show when sending email
      • Email address: Yahoo Mail address
      • Account Type: IMAP
      • Server information: match the Yahoo Mail IMAP settings
      • User Name: Yahoo ID
      • Password: Yahoo account password
      • Require logon using Secure Password Authentication: OFF
    5. More Settings > Outgoing Server tab
      • My outgoing server (SMTP) requires authentication: ON
      • Use same settings as my incoming mail server: ON
    6. Advanced tab settings:
      • Incoming server (POP3) 
        • imap.mail.yahoo.com
        • port: 993 
        • encrypted connection: SSL
      • Outgoing server (SMTP) 
        • smtp.mail.yahoo.com
        • port: 587 
        • encryption type: TLS
    7. Restart Outlook
    8. Send/Receive All Folders to sync


    Upgrade Windows 11 Home to Windows 11 Pro

    Disable internet connection (Wi-Fi, Internet, etc.) Change the product key using the following Generic product key:                     VK7J...