Wednesday, February 18, 2009

My website works on my machine, but it won't work on GoDaddy. How come?

Okay, as I said in my last post, I see a lot of posts in forums and newsgroups dealing with web development that are somewhere along the line of the title.  And it may be GoDaddy, or it may be some other shared hosting company.

I started writing this post about a week ago, and trying to recount my experiences chronologically became too long and rambling, so let me just list some of the problems that I have encountered.  I may expand on some of them in future posts.

1. You don't have control of your execution environment on a shared hosting service like you do when you're running on your own machine. You don't have control over what software has or hasn't been installed, or what the machine configuration settings are, etc. The first problem I encountered was that I had installed the MySql Connector that interfaces the .NET framework to a MySql database.  GoDaddy hadn't, or at least didn't have the same version that I had and that my program was expecting. (And they couldn't or wouldn't tell me what version, if any they did have.)  The work around is to make sure your program/website is completely self-contained, so that you're not relying on anything on their environment (in my case, by copying the MySqlData.dll into the "bin" directory of the website I was publishing to GoDaddy).

2. You're running in what is known as a "medium trust" environment in a shared hosting server.  Chances are, unless  you have deliberately configured it, your development and  test environment is a "high trust" environment.  What this basically means is that there are a whole  lot of perfectly legitimate things that your program might want to do that are simply not allowed in the medium trust environment.  This is worth a whole post of its own, but just let me say that, if you're going to be hosting your site on a shared hosting server, set up your development and test environment  for medium trust (I'll cover how in another post.  For now, if you need to know how, google it.)  You will save yourself a whole lot of headaches.

3. The database servers are probably different in some respects from what you're running on in development.  This will be particularly true in the case that you're using MySql (which I was), rather than Microsoft SQL Server (MSSQL).  There are two noticable differences, even though I was running MySql in my development environment as well. 

One is that the MySql server that was in my development environment was running on a Windows machine.  There's is running on a  Linux server.  Yes, the web server is hosted on a  Windows machine, but the database that it connects to is running on a  separate machine which is Linux.   The  key difference is that MySql on Windows is not case sensitive, while on Linux it is.  So a command like "SELECT productID FROM Products WHERE Sku=@Sku"  will work fine on a Windows base MySql Server, even if the columnname is actually productid and the table name is products.  But it will fail if that same database is hosted  on a  Linux server.

The second area of concern is that the security is much tighter on GoDaddy's database servers. Specifically, you cannot access anything outside of the database you're connected to, even if you have permissions for it (I'm  not sure how you would specify permissions for it.)  As a result, you are not even permitted to specify the database property of a table.  If you're not  aware of it, this can be a problem, because the MySql Connector that  interfaces with Visual Studio, by default, generates insert, update and delete commands that reference the tables as <databasename>.<tablename>  (E.g., INSERT INTO MyDB.Customer (CustomerName, ...) ) Even though the databasename is, in fact, the database that you are connected to and working with, simply specifying the database name will  kick the statement out on a permissions violation.  (The first time I saw this error, it said something like my Insert statement failed because I didn't have proper permissions, and I was on the phone complaining irately to GoDaddy Support that they had set up my database without giving me write access into my own tables!  It took  me a while to understand exactly how it worked.)

Another area where this comes into play is that, when you're dumping and restoring a database, you may have to edit the SQL that's generated to remove certain parameters.  When you define a View, the MySqldump will dump the CREATE VIEW statement with a "DEFINER" attribute.  Even  though the DEFINER is you, that will cause the statement to fail if you try tor use it to  restore the database on GoDaddy's servers.

Also, GoDaddy, allegedly for "security reasons" will not permit you to define your own stored procedures in your database (and don't tell you that until you try it and it fails with some obscure error!).  I'm not that good with databases, and so far, I've only had one instance where I was trying to use a stored procedure.  Fortunately, I was able to program around that one fairly easily.


So,  those are the three main areas.  There's probably some small incidents here and there that fall outside those bounds.  But that covers most of it.  And there are ways to work around all  of them. It's just a question of  how much work   you have to go through to do it.

I will try to expand on the "medium trust" issue in  another post.


Saturday, February 7, 2009

Hosting a Website on GoDaddy

I'm going to make this short right now, and post more in future days, hopefully.

One of the reasons I started this blog was to share what I had learned about hosting a website that I've developed on a shared hosting service, specifically, GoDaddy.com. 

In reading various ASP.NET forums, I am constantly seeing posts that say something like "I developed this website, and it works great on my development server, but it won't come up at all (or misbehaves in some particular way) when I port it to my hosting service."  Which was exactly my experience when I brought up my first site nearly a year ago.  And I solved a lot of problems, one at a time, and learned a lot, before I got it running. (BTW, it's broke right now, and I'm working on finding time to get it fixed.  Soon.)

But before I do post any of those lessons, I wanted to share a post made earlier this week by Joe Stagner of Microsoft. It's a 45-minute video on
Creating, Updating, and Publishing Web applications with Visual Web Developed Shared Hosting.

In it, he goes through the mechanics of loading your site to your hosting service, establishing your database, administering your site etc.  The particulars vary depending on your hosting company (and, unfortunately, none of them are remotely close for GoDaddy) but the basic idea is there.

I was disappointed that he did not go into some of the development issues to keep in mind - things you are allowed to do on your own machine that are guaranteed to break spectacularly when you put your application in a shared hosting environment.  But maybe he will in subsequent installments.  He did say this was the first of a series.

And, if not, all the more reason for me to write my posts...

Wednesday, February 4, 2009

Facebook

I have a confession!  Until recently, I was not on facebook!

It really was more that I just couldn't be bothered than that I was actively resisting.  But I kept getting more and more invitations from friends, and discovered that you really couldn't nose around and see anything about what your friends were doing unless you had an account there.  (Fair enough, I suppose.)

So, a few weeks ago, I relented and created an account.  And since then, I have been amazed at the number of people that I really do know that are there.   Some that I haven't seen in 40 years!  But I'm even more amazed at the number of times it (facebook) will suggest that I might know someone, and way more often than not,  they're right.  And I scratch my head and say, how on earth does it know that?

Be that  as it may, it appears that facebook is becoming (or has become) something of a phenomenon.  My friend George Hillman posted an entry on his blog the other day which caught my eye: Why aren't you on Facebook? In it, columnist Farhad Manjoo says that facebook has followed a similar evolution to that  of the cellphone - from an elitist gadget to something that is simply expected.  Facebook recently announced reaching a milestone of 150 million user accounts.

Anyway, I'm enjoying catching up with a lot of people that I wouldn't have otherwise.  There are certainly some objectionable possibilities, Mark Davis points out, you have complete control over what you do  with it and what you make of it.