Monday, 24 September 2012

Add SQL Azure as Linked Server

Just a quick note on how to set SQL Azure on your local SQL Server as Linked Server.

EXEC sp_addlinkedserver
@server='LinkServerName',
@srvproduct='',
@provider='sqlncli',
@datasrc='ServerName.database.windows.net',
@location='',
@provstr='',
@catalog='DatabaseName'

EXEC sp_addlinkedsrvlogin
@rmtsrvname='LinkServerName',
@useself='false',
@rmtuser='username@ServerName.database.windows.net',
@rmtpassword='Password'

EXEC sp_serveroption 'LinkServerName', 'rpc out', true;

I added user@ServerName because I kept on getting error from SQL Azure.

Server name cannot be determined.  It must appear as the first segment of the server's dns name (servername.database.windows.net).  Some libraries do not send the server name, in which case the server name must be included as part of the user name (username@servername).  In addition, if both formats are used, the server names must match.



Tuesday, 17 January 2012

Get Mouse Pointer Position

Get the mouse pointer position by Imports System.Windows.Forms
and assign the Cursor.Position.ToString() to any control you wish to :)

Thursday, 12 January 2012

GIT User error after re-installing windows

if you have reinstalled your computer and found after GIT setup first publish that your username is showing as unknown you might need the following steps to correct the issue.

Did you try to set the user name with the following commands:
// global settings
$ git config --global user.name "FirstName LastName"
$ git config --global user.email "user@example.com"
or
// for a specific project
$ git config user.name "FirstName LastName"
$ git config user.email "user@example.com"

Edit: global settings are stored in the folder designated by the HOME environment variables, which should be unique for each Windows user, so you will have real data about the logged in user.

Git Host Key Verification Failed Error

if you re-formatted your computer like me and faced errors with GIT, you might need the following steps to setup the ssh key again.

1. Set your global settings first:
git config—global user.name “Your Name”
git config—global user.email “email@email.com
Your email address must be same as in Assembla

2. Generating a new key:
ssh-keygen -t rsa -C “name@email.com
Do not give it a filename. Just hit enter.
Creates a public and private key. Will ask for passphrase but you don’t need one. Just hit enter.

3. In Windows, the key will appear at C:\Users\name\.ssh on default
Copy public key (rsa_id.pub) into your Profile on Assembla
Best way to do this is to open it in Notepad and save it as rsa_id.txt without making any changes. Then upload it to your profile.

Wednesday, 4 January 2012

Validate Email using RegEx

Dim regex As New
System.Text.RegularExpressions.Regex("^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$")
Dim match As System.Text.RegularExpressions.Match
match = regex.Match(myEmail)

If Not match.Success Then
ErrorMsg = ErrorMsg & "Email Not Valid"
End If

Friday, 28 October 2011

Javascript to disable all ASP:ImageButton

if you want to disable all <ASP:ImageButton type controls using Javascript, you have to keep in mind that browser renders the controls this way

<input type="image" name="ctl00$btnUserHistory" id="btnUserHistory" title="User Activities" src="/Img/userhistory.gif" />

You see ctl00$ in the name as the button is inside a ContentPlaceHolder, so catch all inside or not write this function

function disableButton() {
        //Disable All Image Buttons       
        var ButtonsColl = document.getElementsByTagName('input');
        for (i = 0; i <= ButtonsColl.length - 1; i++) {
            if (ButtonsColl[i].getAttribute('type') == 'image') {
                ButtonsColl[i].disabled = true;
            }
        }
    }

Tuesday, 25 October 2011

Convert SSL Certificate .cer to .pfx

If you were like me working on Azure projects and suddenly was required to upload your SSL certificate and hit the dead end trying to figure out how to convert the file to .pfx, you have come to the right place, follow these simple steps and you'll be good to go.

PowerShell Script
$c = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\mycert.cer")
$bytes = $c.Export("Pfx","password")
[System.IO.File]::WriteAllBytes("c:\mycert.pfx", $bytes)

and just incase if you got the error cannot find type [System.Security.Cryptography.X509.....

Try running this to see if you have the System.dll loaded (should be by default):
[AppDomain]::CurrentDomain.GetAssemblies() |
    Where {$_.Location -match '\\System\\'}

If it is loaded then this command should show the X509Certificate2 type:
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'} |
%{$_.GetExportedTypes()} | Where {$_.Name -match 'X509Cert'}
If the System.dll isn't loaded (which would be odd) try loading it:
Add-Type -AssembyName System