Create a Jira Issue/Checkout a corresponding branch. Easily.

A common development flow goes like this:

  • Create a Jira ticket
  • Create a Git branch mapping to that Jira ticket
  • Making changes in the branch, and then merging it into master using a pull request

The initial set up can be quiet annoying because first you have to go to your Jira website and create an issue, possibly first having to navigate to the correct project etc., and then you have to go to your Git software/command line or github.com and create a new branch. Wouldn’t it be nice if you could achieve all that from right within Visual Studio or from the command line, by issuing just one command?

That is exactly what this tool does.

You can look/get the code from here

https://github.com/floatingfrisbee/CIC

or download the zipped binaries from here:

https://github.com/floatingfrisbee/CIC/releases

The tools uses the Jira REST API to create an issue and then invokes git.exe locally based on the response received as a result of the Jira call.

If you want to add this to Visual Studio’s External Tools, you should put the files in your path somewhere, and go to Tools -> External Tools and “Add” a new tool with the following settings:

Command: cic.exe
Arguments: -u <username> -p <password> -k <JiraProjectKey> -r $(SolutionDir) -t "Your Jira Ticket's Title"

Create a Jira Issue/Checkout a corresponding branch. Easily.

Solving SQL Server connectivity issues (including on instances installed on Azure VMs)

UPDATE, dated 14th March 2015

The link below has a list of things to check to resolve connectivity issues. Worth taking a look if you are stuck with an SQL Server that you cannot access remotely.

http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/

UPDATE, dated 3rd February 2015

One of our clients uses SQL Server 2005 and so to test the scenario we set up an Azure VM with SQL Server 2005 Express. Even though we followed the steps mentioned in the link below, we could not access the SQL Server remotely. Eventually on opening the “SQL Server 2005 Surface Area Configuration Tool”, I discovered that SQL Server 2005 Express edition does not allow remote connections.

SqlServer2005SurfaceAreaConfiguration

Not sure if this is true of all versions of SQL Server but if you want to remotely connect to the server, I would stay away from the Express editions.

Also, if you are using SQL Server 2005, check out this link in addition to the one below, for instructions on what must be done to enable remote connections to the SQL Server.

http://support.microsoft.com/kb/914277


If you’re trying to set up an SQL Server instance in the Azure cloud, you will want to check out this link.

http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-provision-sql-server

It lists the steps you need to take in addition to setting up a VM with SQL Server on it.

PS: By “Setting up an SQL Server instance in the Azure cloud”, I mean a VM where you can run your own SQL Server, as opposed to a “Platform as a Service”, Azure SQL Server (which has some inherent limitations).

Solving SQL Server connectivity issues (including on instances installed on Azure VMs)

Mootools & JQuery Ajax calls to an ASP.NET MVC Application

It’s been a while since I’ve messed around with some good ol’ Mootools and JQuery. I hope they’re still in fashion!

This project demonstrate something very simple and something that probably every web application out there has to do nowadays… make ajax calls from JavaScript to a backend  service. Both Mootools and jQuery provide wrappers around that functionality but it can be annoying to get started with them especially when you want to POST different kinds of data – simple strings and numbers, complex objects and lists etc.

The code is on GitHub (you can also download a .zip file from this link)

https://github.com/floatingfrisbee/MooToolsAndJqueryServiceExample

Not much more to say but if you check out the project (an ASP.NET MVC 3 application build using Visual Studio 2010) it is a minimalistic demonstration of what headers you need to set, what additional encoding (using json2) you need and a couple of other nuances.

Here are Mootools calls

// Call a service that takes a simple string as input
function simpleMoo() {
    var args = new Object();
    args.stuff = 'A Compact JavaScript Framework';

    var req = new Request.JSON({
        url: '/home/savestuff',
        method: 'POST',
        onSuccess: OnSuccessMoo,
        onFailure: OnFailureMoo,
        data: args
    });

    req.send();
}

// Call a service that takes an object with a sub object as an argument
function complexMoo() {
    var args = new Object();
    args.Name = 'Vince';
    args.Age = 34;
    args.Address = new Object();
    args.Address.Street = '32 E 23RD ST APT F';
    args.Address.City = 'New York';
    args.Address.State = 'NY';
    args.Address.Country = 'USA';

    var req = new Request.JSON({
        url: '/home/savecomplexstuff',
        method: 'POST',
        onSuccess: OnSuccessMoo,
        onFailure: OnFailureMoo,
        urlEncoded: false
    });

    req.setHeader('Content-Type', 'application/json; charset=utf-8');

    req.send(JSON.encode(args));
}

// Call a service that takes a list as an argument
function listMoo() {
    var args = new Object();

    args.listOfStuff = [];
    args.listOfStuff[0] = "Christoph Pojer";
    args.listOfStuff[1] = "David Walsh";
    args.listOfStuff[2] = "Darren Waddell";

    var req = new Request.JSON({
        url: '/home/savealistofstuff',
        method: 'POST',
        onSuccess: OnSuccessMoo,
        onFailure: OnFailureMoo,
        urlEncoded: false
    });

    req.setHeader('Content-Type', 'application/json; charset=utf-8');

    req.send(JSON.encode(args));
}

And here are the JQuery calls

// Call a service that takes a simple string as input
function simpleJQuery() {
    var args = new Object();
    args.stuff = 'Write Less Do More';

    $.ajax({
        url: '/home/savestuff',
        type: 'POST',
        data: args,
        success: OnSuccessJQuery,
        error: OnFailureJQuery
    });
}

// Call a service that takes an object with a sub object as an argument
function complexJQuery() {
    var args = new Object();
    args.Name = 'Vince';
    args.Age = 23;
    args.Address = new Object();
    args.Address.Street = '45 W 43TH ST APT E';
    args.Address.City = 'New York';
    args.Address.State = 'NY';
    args.Address.Country = 'USA';

    $.ajax({
        url: '/home/savecomplexstuff',
        type: 'POST',
        data: JSONDC.stringify(args),
        contentType: 'application/json; charset=utf-8',
        success: OnSuccessJQuery,
        error: OnFailureJQuery
    });
}

// Call a service that takes a list as an argument
function listJQuery() {
    var args = new Object();

    args.listOfStuff = [];
    args.listOfStuff[0] = "John Resig";
    args.listOfStuff[1] = "Leah Silber";
    args.listOfStuff[2] = "Adam Sontag";

    $.ajax({
        url: '/home/savealistofstuff',
        type: 'POST',
        data: JSONDC.stringify(args),
        contentType: 'application/json; charset=utf-8',
        success: OnSuccessJQuery,
        error: OnFailureJQuery
    });
}

Hope this help you get going faster!

Mootools & JQuery Ajax calls to an ASP.NET MVC Application

Outlook Unable to Start With an Exchange Account

I had set up a new Exchange Server 2010, and was trying to connect to my account on that server using Outlook 2010. However, I kept getting this error and Outlook was unable to start.

"Cannot open your default e-mail folders. You must connect 
to Microsoft Exchange with the current profile before you 
can synchronize your folders with your offline folder file."

The computer I was using was in the same Windows Domain as the Exchange Server, and I was able to access (remote desktop) the Exchange Server without any issues. I was also able to access my account using the OWA interface without any issues. The only problem was that I could not access it via Outlook.

There are a plethora of blog posts and forums online where users have experienced the exact same error message and many different solutions have been suggested. None of them worked for me until I finally found this one.

While the solution proposed in the post itself did not work for me, one of the comments on the post proposed a solution that did. Waseel Akbari had the following comment:

It worked once for me but later the same problem started again, after too much struggle I found a solid solution and that is:
Go to Exchange server ::> Services ::> Check if this service is started (Microsoft Exchange RPC Client Services) if it’s started give it a restart

This made the most sense to me given the error message and the fact that Outlook uses RPCs to communicate with Exchange Server (whether it is using MAPI RPCs or RPC over HTTPS). You can read this great article about Outlook Anywhere (which is another name for Outlook’s RPC over HTTPS functionality).

So I remote desktop’d into my Exchange server -> Start -> Run -> services.msc and looked for the “Microsoft Exchange RPC Client Access” service and sure enough, it was not running. I started it, and voila, I was able to connect to my Exchange account using Outlook.

Outlook Unable to Start With an Exchange Account

Issues after installing Windows Server 2008 R2 on a laptop

After installing Windows Server 2008 R2 on my laptop, I noticed a couple of things:

  1. On closing the lid of the laptop, it did not go into sleep or hibernate mode, but was instead running and draining power
  2. I could not see the list of wireless connections available, and hence was not able to connect to one
  3. Internet Explorer was in High security level for the Internet zone and I could not change that

All these issues happen because the OS I installed was Windows Server 2008 R2. I guess the defaults associated with that server OS were not really applicable for a laptop.

Here are the fixes:

  1. The obvious place to look was power options inside the Control Panel. I intended to change the “When I close the lid” setting and chose the “Hibernate” option. However it was not an available option. What I had to do first is run the following on a command prompt
    c:\> powercfg.exe /hibernate on

    When I did this, it caused the Hibernate option to show up in the “When I close the lid” setting. I chose that and it just worked.

    This information was obtained from here.

  2. To fix the wireless issue, I ran Windows Diagnostics and like any user expected it not to work. It lived up to expectations. It told me that nothing was wrong. On looking at network adapters, the wireless adapter showed up as enabled. Finally based on this link, I came to know what the issue was. It was that Windows Server 2008 R2 (and probably other servers) doesn’t have wireless access turned on by default, and the “Wireless LAN Service” has to be explicitly started by going to
    Start -> Administrative Tools -> Server Manager -> Features

    and adding the feature with the same name.

    Don’t ask me why Windows Diagnostics would not just give the message “The Wireless LAN service is not running, start it for wireless access”. I’m confounded!

  3. It turns out that in Windows Server 2008 R2 puts Internet Explorer in Enhanced Security Configuration (also known as IE ESC) by default, and when in that configuration, you cannot alter the security setting, and will receive annoying messages whenever you navigate to any site that you have not explicitly added to the trusted list. Also you will probably not be able to download other software like Google Chrome :-). I found the solution here, which is to go to the Server Manager and click on the “Configure IE ESC” link on the right side of the window. Once you turn off ESC, you will automatically be put in “Medium-High” security setting for the Internet zone and can browse normally. Keep in mind that you are lowering the security setting of your machine and hence increasing the probability that your computer is infected with spam ware or a virus, so take the appropriate precautions like installing an antivirus and correctly configuring the firewall.

Anyway, hope this helps.

Issues after installing Windows Server 2008 R2 on a laptop

Mapping a local branch to a remote branch in GIT

If you’ve created a git repository using the following steps:

  1. Created a local git repository using “git init .”
  2. Created a remote repository on github.com or another host
  3. Added that remote to the local repository using “git add remote origin <path to remote repo>”

Then you might be in a state where your local master is not mapped to the remote master. To fix that run the following command:

git branch --set-upstream master origin/master

I suspect that in step 3 there could be a way to specify the mapping so it doesn’t have to be done later explicitly, but I’m not aware of it currently.

Mapping a local branch to a remote branch in GIT

How to add a new database user based on a windows user

Here’s another post based on my gripes against database administration tools and how difficult they are to use (and the fact that so many people seem to be ok with it).

Many people have multiple windows users on their PCs. Maybe one for administration and one for daily usage for example. That’s my setup, I have a “laptop\admin” user and a “laptop\me” user, and recently I was trying to create a new database on my local SQL Express 2008 installation while logged in with my “laptop\me” account. I was using SQL Server Management Studio to do this. Off course, it did not work. Here is the error I got.

“CREATE DATABASE permission denied in database ‘master’. (Microsoft SQL Server, Error: 262)”

What that means is that my “laptop\me” user does not have the permissions to create a new database on my SQL Express instance. OK, no worries, I get that. I should be able to start SSMS as “laptop\admin” and grant the said permissions to “laptop\me”. No such luck. Nothing is that simple in database land.

I’ll cut to the chase and list the steps you need to follow to make that happen.

– Start SSMS as an admin user (right click and choose “Run as Administrator”)

This is assuming that the admin user has the authorization to create a new login and grant the create database permission. To do the database login associated with that admin user will need to be in the “sysadmin” role. More baloney I know! Someone in the team felt that every developer needs to be exposed to the full permissioning machinery just to create a database. If you do not have a login that is in the sysadmin role for the SQL Server instance  you are working with, unfortunately you have to create one. Click here for a link to a blog post that can help you do that. The post is for SQL Server but works for SQL Express also.

– Create a login in the SQL Express instance

USE master
CREATE LOGIN [laptop\me] FROM WINDOWS

– Create a user for that login

USE master
CREATE USER mydatabaseuser FOR LOGIN [laptop\me]

– Grant permission to that newly created user

USE master
GRANT CREATE DATABASE TO mydatabaseuser

Too many steps in my opinion, but hey, how would we have “database guys” if this was easy!!

How to add a new database user based on a windows user

Yui Compressor issues with reserved words in JavaScript

For the life of me, I could not figure out why I was getting an error while running the Yui compressor on a set of my JavaScript files.

The error was very generic and not helpful

error : Failed to read in the data for the path/file [..\<path>\<filename>]. The most common cause for this is because the path is incorrect or the file name is incorrect … so please check your path and file names. Until you fix this up, I can’t continue … sowwy.

The file was present and seemed to be syntactically correct and all.

Finally, thanks to a little squiggly placed by Resharper (which is awesome!!), I found the issue. One of the js functions was called “goto” and that, apparently is reserved by JavaScript for “future use”, and Yui bombs on it.

Renaming it fixed the issue.

UPDATE

To be clear, the YUI compressor is behaving as it was designed to. Reserved words should not be used in JavaScript, as in other languages. However, I will say that the error dumped out when the compressor runs into a reserved word could be better.

Yui Compressor issues with reserved words in JavaScript

Crazy Idea of the Day – Product Placement in Google Streeview

I was looking up the street view for the Met, and this is what the view from Columbus Avenue looks like. Fresh Direct guys are every where in NYC but not so sure this was unintentional! That’s some prime product placement for a great NYC Startup.

Just FYI, this is on 02/20/2012.

Crazy Idea of the Day – Product Placement in Google Streeview

SQL Server 2008 – Creating a database from a .bak file

I’m not a database expert!

Every so often I run into something that seems so simple that should just work but doesn’t. Searching for solution is a tedious chore of sifting through jargon and unclear explanations, somehow more so in database land than with other technologies… what is it with these “database types”?

Anyways, creating a database from a .bak file was one of those things. In SSMS, it should really be as simple as

1. Choose the .bak file
2. Give a name to the destination database
3. Press Go

But it’s not. Yes, there are probably good reason for it… actually no, all those good reasons are just travesty!

By default, you can only restore databases from .bak files that were created from them. If you try to do something else, you will get the following error.

Similarly if you try to restore using T-SQL

RESTORE DATABASE newdatabase
FROM DISK = 'c:\DatabaseBackups\dev2012021601.bak'

You will see the following error if the database “newdatabase” already exists

Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'jb' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

or something like this one if it doesn’t already exist

Msg 1834, Level 16, State 1, Line 1
The file 'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\devdb.mdf' cannot be overwritten. It is being used by database 'devdb'.
Msg 3156, Level 16, State 4, Line 1
File 'dbname' cannot be restored to 'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\devdb.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 1834, Level 16, State 1, Line 1
The file 'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\devdb_1' cannot be overwritten. It is being used by database 'devdb'.
Msg 3156, Level 16, State 4, Line 1
File 'devdb_log' cannot be restored to 'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\devdb_1.ldf'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

If that’s where you are stuck, the following will help you.

1. In SSMS, open  a query window in the master database of the database server. That’s where you will run the following queries.

2. See what the “LogicalName” of the database that has been backed up in the .bak file is 

RESTORE FILELISTONLY 
FROM DISK = 'c:\DatabaseBackups\dev2012021601.bak'

This will give you the logical name of the database and its associated log file. Lets assume that the names are “dbname” and “dbname_log”

3. Now run the following restore command. Make sure that a database with the name you are trying to create doesn’t already exist (in the code sample below, dbForSocialMigration doesn’t exist).

RESTORE DATABASE dbForSocialMigration 
FROM DISK = 'c:\DatabaseBackups\dev20120307.bak' 
WITH 
MOVE 'dbname' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\dbForSocialMigration.mdf', 
MOVE 'dbname_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\dbForSocialMigration_log.mdf'

 C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA is the directory where SQL Express usually keeps its data files. You can find the directory your database server is using by selecting a database from it, right clicking and opening the properties dialog and selecting the “Files” option from the left.

That should work, and at that point you should be able to access the database “dbForSocialMigration” populated with all the tables and data from the .bak file.

Good Luck!

SQL Server 2008 – Creating a database from a .bak file