Connecting to MS SQL Server from Ubuntu

And now, in a break from the previous trend of fluffy posts, we have a tutorial on how to (deep breath): connect PHP to a MSSQL Server 2008 instance over ODBC from Ubuntu Linux using the FreeTDS driver and unixODBC. Theoretically it would also work for SQL Server 2005.

I don’t know whether half of the settings flags are necessary or even correct, but what follows Worked for Me™, YMMV, etc, etc.

In the commands below, I’ll use 192.168.0.1 as the server housing the SQL Server instance, with a SQL Server user name of devuser, password devpass. I’m assuming SQL Server is set up to listen on its default port, 1433. Keep an eye out, because you’ll need to change these things to your own settings.

First, install unixODBC:
sudo apt-get install unixodbc unixodbc-dev
I also installed the following (perhaps necessary) packages:
sudo apt-get install tdsodbc php5-odbc
Then download, untar, compile, and install FreeTDS (warning, the URL may change):
cd /usr/local
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar xvfz freetds-stable.tgz
cd freetds-0.82
./configure --enable-msdblib --with-tdsver=8.0 --with-unixodbc=/usr
make
make install
make clean

Attempt a connection over Telnet to your SQL Server instance:
telnet 192.168.0.1 1433

Use the tsql tool to test out the connection:
tsql -S 192.168.0.1 -U devuser

This should prompt you for the password, after which you can hope against hope to see this beautiful sign:
1>

If that worked, I recommend throwing a (coding) party. Next up is some configging. Open the FreeTDS config file.
/usr/local/etc/freetds.conf

Add the following entry to the bottom of the file. We’re setting up a datasource name (DSN) called ‘MSSQL’.
[MSSQL]
host = 192.168.0.1
port = 1433
tds version = 8.0

Now open the ODBC configuration file:
/usr/local/etc/odbcinst.ini

And add the following MSSQL driver entry (FreeTDS) at the end:
[FreeTDS]
Description = FreeTDS driver
Driver = /usr/local/lib/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so
FileUsage = 1
UsageCount = 1

Then, finally, set up the DSN within ODBC in the odbc.ini file here
/usr/local/etc/odbc.ini
By adding this bit to the file:
[MSSQL]
Description = MS SQL Server
Driver = /usr/local/lib/libtdsodbc.so
Server = 192.168.2.3
UID = devuser
PWD = devpass
ReadOnly = No
Port = 1433

Test out the connection using the isql tool:
isql -v MSSQL devuser 'devpass'
If you see “Connected!” you’re golden, congratulations! If not, I’m truly sorry; see below where there are some resources that might help.

Now restart Apache and test it from PHP using ‘MSSQL’ as the DSN. If something doesn’t work, you might try installing any or all of these packages:
mdbtools libmdbodbc libmdbtools mdbtools-gmdb

Here are some other resources that were helpful to me through this disastrous journey.

Posted in Compute | Leave a comment

Most Common Navigation Fonts

I did a quick font check on some of Alexa’s top sites to see what the consensus was for navigation fonts. The results are below for the curious and for my own future reference, showing the most likely fonts to be displayed on a Windows machine. If they weren’t Arial or Verdana I listed the fallbacks.

  • LinkedIn: Arial 13px
  • Flickr: Arial 13px
  • PayPal: Arial 12px
  • Microsoft: Tahoma, Verdana 11px
  • IMDb: Verdana, Arial 13px
  • BBC: Arial 12px
  • WordPress: Arial 14px
  • Facebook: Lucida Grande, Tahoma, Verdana, Arial 11px
Posted in Compute | Leave a comment

How to Rename Google Maps Starred Places

Recently I’ve been looking for a way to rename the Places I have starred in Google Maps, since that feature was yanked from the Blackberry Google Maps app. It turns out your Google Bookmarks page lets you do this; there, you can rename whatever entries you like. This makes my places with stars much more useful — I can change unintuitive titles like “1175 Peachtree” to something like “PHP Meetup.”

Posted in Compute | 5 Comments

Verizon Fivespot WiFi Connection Issues

Recently I was setting up a brand new Toshiba laptop (running Windows 7) to use the WiFi hotspot created by Verizon’s Fivespot, but I ran into a persistent ‘security code mismatch’ issue. Hours of diagnostics later, I came across the workaround which, while not perfect, will work for now.

The Problem

Even though the laptop could see the wireless hotspot, when you entered the security code on the back of the Fivespot, it gave a ‘security code mismatch’ every time — even though other devices could connect to the Fivespot network just fine, and this laptop could connect to other wireless networks just fine. Adding to the peculiarity, if connected via USB to the laptop using the WWAN connection, it worked just fine.

The Workaround

(The tech professional version: Connect to the WiFi hotspot on another computer. Visit 192.168.0.1 with ‘admin’ as the password and change the encryption mode to WEP. Enter a passcode, then apply. Restart the Fivespot. Connect from your device using the passcode.)

You’ll need a different computer that can successfully connect to the WiFi hotspot. I used another laptop for this, but it could be anything with a full browser — iPad, Blackberry, just whatever will connect. Go ahead and connect to the Verizon AC30 network on that device.

Type 192.168.0.1 into your browser. When it asks you for a password, type ‘admin’, just like the username. Click Basic Setup at the top. On the drop-down for Encryption Mode, change it to WEP, then make up a password to fill in to Network Key 1. Click Next, then Apply. You can then close that page. Note that while using WEP mode means your network will not be open, it is not really that secure.

Next, to get the hotspot to show up correctly, I had to restart the Fivespot. Once the Verizon AC30 network shows up on your (formerly nonworking) laptop, connect and use your chosen Network Key as the password when it prompts you.

According to a very helpful Verizon employee who knew the workaround, they know about the issue, and they’re collecting details to be able to issue a firmware update to the Fivespot. Hopefully this will come soon.

Posted in Compute | 2 Comments

Just checked up on my Google Reader statistics.

From your 65 subscriptions, over the last 30 days you read 1,255 items, clicked 166 items, starred 3 items, shared 1 items, and emailed 0 items. Since November 22, 2006 you have read a total of 16,742 items.

The ‘2006’ part of it makes the numbers seem off… since at the stated rate of consumption, I should have read more like 85,000 items. I didn’t pick up serious Google Reader usage until a couple years ago. I’m clearly not much of a share-er, but that’s mostly because it feels awkward sharing with all of my followers things that me and probably two other people would find interesting.

Posted in Aside, Compute, Myself | Leave a comment

Verizon’s PR Disaster

Recently I was reading an article titled Family, Verizon far apart over nearly $18,000 phone bill; basically, a college kid thought his family’s unlimited data plan was still in effect, and downloaded a little over 1 GB over the network, only to find out that they were being charged at a rate of $15 per MB (the homepage of Amazon.com is 0.9 MB).

Just to illustrate how ridiculous this scenario would be in any other market, here is an equivalent story where data == water.

Imagine that you get your water from a little company called Verizon. They normally supply water at a price of $100 per month for an unlimited amount, but for the past 2 years they’ve given you a promotional deal where you get unlimited water for free. Your son has a garden and uses quite a bit of water for irrigation, but it’s fine — after all, you have limitless water for free.

One day you get a bill in the mail from Verizon for $18,000. You had (understandably) forgotten that your 2-year promotional deal had ended 2 months ago. Now, this bill staring back at you says that since you did not have the $100/month unlimited plan for the past 2 months, you must pay for your water usage at a rate of $10 per cup, for a total of $18,000.

Should you have to pay the whole bill? Based on the above scenario, the answer to is quite obviously no, so the real question is:  if not $18,000, how much should you have to pay? Even that is pretty clear: 2 months for unlimited water at $100 per month, for a total of $200, plus tack on some silly management fee for rolling you over into the unlimited water plan, giving $225 as the grand total. Water works as a fairly accurate and handily intuitive comparison to data transfer — most of the differences between the two are not relevant here.

At first, this news report was rather infuriating, since an innocent family was to be burdened with a $18,000 debt for no good reason. After more thought, it is simply puzzling as to why Verizon thinks it’s a good PR move to defend its position. And the story above makes it more than apparent how overages like this one should be handled — it’s not as if the water coming out of your tap will ever suddenly go from costing $0.02 per cup to costing $10 per cup, because you used beyond your monthly limit.

Consumers should demand a stop to being tricked into giving telcos extra money for something that has a marginal cost equal to its non-marginal cost.

Posted in Compute | Leave a comment