Thursday, January 22, 2015

SQL Server: Link two Databases from two different SQL Servers



How to link Two SQL Servers

Execute the following system Stored Procedure to create new SQL Server that you want to link to: 

sp_addlinkedserver 'TestServer1','','SQLNCLI','192.199.121.12\SQLEXPRESS',null,NULL,NULL 

Now, by executing the first command, your linked server is created. But still you need to create the user to login to that linked server. To do this, execute the following system Stored Proc: 

exec sp_addlinkedsrvlogin ' TestServer1','false',null,'username','password' 

 Now, try to run the any query of the database connected to that linked server

E.g: Select * From TestServer1.DatabaseName.[dbo].tableName

Wednesday, January 21, 2015

Autocomplete Location Search using Google API in .Net Jquery

The following code is implemented in Razor MVC:

1. _TestView.cshtml
<script src="https://maps.google.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
/*
Your JQuery Files
*/
<div>
/* Your View Code */
.
.
.
.
<input id="txtLocation" type="text" />
</div>



2. Jquery Code:
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
    var input = document.getElementById('textbox_Location');
    var autocomplete = new google.maps.places.Autocomplete(input);


    google.maps.event.addListener(autocomplete, 'place_changed', function () {

        var place = autocomplete.getPlace();
        if (typeof (place.address_components) !== 'undefined') {
            //Saved location
            var placeName = place.name;
            var completeAddress = place.formatted_address;
            var latValue = place.geometry.location.lat();
            var lonValue = place.geometry.location.lng();
        }      
        return false;
    });
}