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.

Thursday, January 29, 2009

This shouldn’t be that hard!

For any of my vast number of readers (hah, hah) who have been following this blog, this post is more what I intended when I decided to start blogging, but so far, haven't gotten around to – a recounting of dealing with a technical issue.

So if you're not into software development, this will doubtless leave you cold, and you're forgiven if you want to go read something more interesting.

For the past 3 days I have been struggling to do something in Microsoft ASP.NET that should be duck soup. But it ain't.

I have a 24x7 array of data that I want to present and edit in a GridView.

Now, a GridView being a presentation control composed of a number of rows and a number of columns, one would think at first glance that he could simply set the DataSource to the array, and, voilá, it would appear. Not so.

In the end, the solution is not too, too terrible, but arriving at it is. This is owing in large part to the state of documentation of today's software products.

They come with megabytes and megabytes of hyper-linked references and how-to walkthroughs, which is great if the task you want to accomplish is exactly one of the walkthrough topics. But if not, you're left to try different combinations of words in various online and offline search engines and hope you hit a combination that lands on an article that somebody has fortuitously written that describes your plight, or something relevant to it.

Now, the Visual Studio Help file entry for "GridView" tells you:

The GridView control can be bound to a data source control (such as SqlDataSource, ObjectDataSource, and so on), as well as any data source that implements the System.Collections..::.IEnumerable interface (such as System.Data..::.DataView, System.Collections..::.ArrayList, or System.Collections..::.Hashtable).

(An IEnumerable is basically anything whose members you can sequence through one at a time – including an array.)

But then it goes on and tells you that there are two different ways to bind to the datasource, depending on which type you're using – a data source control, or an IEnumerable. And there's the first hint of difficulty.

The GridView is really designed to work with data from a database, and when you use it that way, everything just goes, point, point, click, click, and it just works. But when you start trying to figure out how to use it with arrays, you're just kinda left in the dark. Searching help files for "GridView binding to array" yields a bunch of articles and hyperlinked references on binding GridViews … to DataSource controls. I never could find a walk through on how to use it with an array.

When you bind to a Database data source (from now on referred to, as Microsoft does, as a "Data Source Control"), the binding goes in the aspx declarative markup, so it's there automatically each time the page is loaded. When you bind to an array, you have to set it programmatically, which basically means that you end up starting all over each time the page is loaded, including when anyone clicks on a button or link on the page.

I'm gonna cut to the chase here and skip dragging you through all the stumbling around that I did … partly in the interest of time, partly so I don't make myself look excessively stupid.

Yes, GridViews can be bound to arrays, although, at least not that I could find, to 2-dimensional arrays, at least not in the way that I wanted to. The thing is that you have to do everything just right, and if you don't, you're rewarded with … nothing. It just simply doesn't work, and you have no clue why.

The first thing is that, while a GridView looks like it would display a 2-dimensional array nicely, it really displays a one-dimensional sequence of objects (in its rows). The columns that it displays have to be Properties of the objects. Not just elements, but properties. Thus, one of my early attempts, for a programming exercise, involved an array of product elements:


public
class
shortProduct

{


public
int id;


public
string sku;


public
string name;


public
decimal cost;


public
bool fractional;


public
decimal weight;

}


I tried to bind an array of those to a GridView (actually, that was a Windows Form project, so it was a DataGridView, but it's the same principal), and got nothing, because those elements (id, sku, etc.) are just elements and not properties. When I converted them all to properties, and bound it to the control, they came up pretty as you please.

But that's a problem when you have a 2-dimensional array of simple elements. What I ended up doing was re-mapping it to an array of 7 objects, each of which was an array of 24 booleans. And then I defined 24 separate properties corresponding to each one of the Booleans. Now I could display it in a datagrid. Clumsy, but it worked:

public class ValidTimeDay

{

private bool[] _validTimeArray;

public bool ValidHour0 { get {return _validTimeArray[0];} set { _validTimeArray[0] = value}}

public bool ValidHour1 { get {return _validTimeArray[1];} set { _validTimeArray[1] = value}}

etc. down to

public bool ValidHour23 { get {return _validTimeArray[23];} set { _validTimeArray[23] = value}}


}


Now I had an object I could display in the GridView. I then mapped each of the 7 rows into one such object, and made the 7 objects into an array, and I could bind to it.

The other area where the GridView makes it difficult to work with arrays is in the editing features. Again, when you're working with Data Source controls, enabling editing of the data is pretty much point, point, click, click. Because the array doesn't have any kind of programmatic insert/update/delete interface, the GridView basically throws up its hands and leaves it up to you. You can get an Edit button on your GridView with just a few clicks, but everything else is up to you. You have to write the program code for handling each event in the process. And one thing that cost me about half a day of stumbling around until some kind soul on a forum gave me an example, the first thing you have to do is tell it what it's editing – even though it just told you . In your "RowEditing" event handler, the first line should be something akin to "GridView1.EditIndex = e.NewEditIndex". If you don't do that, nothing else happens! You also have to write the code to go back into the child controls of the GridView and figure out exactly what changes were made and store them in the array- that doesn't happen automatically either.

Once you know how to do something, it's not all that hard. It just shouldn't be that dang hard to figure out.




Monday, January 19, 2009

My first cruise




I’m writing this in the car on the way back from my first cruise. It’s something I’ve wanted to do for a long time, and let me say, right up front, I’m glad I went and I had a good time.

But it didn’t really meet my expectations, and I doubt I will go again. The problem may have been with my expectations, or it may have been with the cruise.

For one thing, at least in my mind, when one says “Caribbean Cruise”, one pictures, well… a CARIBBEAN cruise. Caribbean as in, primarily, warm, and with white sand beaches and blue water.

We left Dallas at 6:30 in the morning with the temperatures in the 20s. And while the cruise was certainly warmer than we left in Dallas, it didn’t match up with my mental picture of WARM. But I should have realized, even though we’re going to the Caribbean, we’re starting the voyage from Galveston, a scant 300 miles south of Dallas. Plus the same cold front that had sent temperatures plummeting in Dallas had pushed its way on south. While the temperature as we boarded the ship was in the 50s, there was a stiff north wind that kept me in sweatshirts and jackets nearly the whole trip.

So I guess the lesson to learn from that is, don’t plan a cruise out of Galveston in the middle of January if you’re expecting warm weather!

That same wind kept the seas rough. The ship was rolling from side to side, to the point where I had the sensation that I was going to roll right out of the bed. While I’m usually pretty good about motion sickness, by 3:00 PM of our first full day at sea, I was huddled in bed to keep from hurtling my lunch. Nancy, my girlfriend, went to the infirmary and brought back some motion sickness pills, which alleviated the sensation, but also virtually knocked me out till 8:00 the next morning.

The consolation, though, is that several cruise veterans said that was the roughest they had seen the seas on any of their cruises. So if I were to go again, that experience probably wouldn’t be repeated.

Overall, the cruise was very relaxing and enjoyable. I got to see a couple of beautiful sunrises (see photo) and sunsets over the water. The food was plentiful, and was certainly good, though I wouldn’t consider it superb. About on a par with what you would expect from your typical casual dining restaurant. However, the claim I have often heard that you can find something to eat at any hour of the day or night turned out to be not quite true, unless you count soft-serve ice cream. We went in search of some at 4:00 one morning, and the ice cream machine was about the only thing we found stirring.

While the weather in Cozumel was somewhat warmer (mid 70s), the same wind still dogged us, and it was cloudy, so I wasn’t really inclined to hit the beach with the few hours we had in port.

While there were certainly enjoyable activities on the ship (dancing, clubs, shows, parties, etc.), I guess I would much prefer, if I’m going to a Caribbean destination, to get there and spend the time on the beach or in the water, rather than spend a day and a half at sea (even if it’s enjoyable) each way to get a few hours at the destination.

But, at least I got to go, and that’s something I can cross off my list of things I’ve always wanted to do!

Monday, December 15, 2008

On Relating to God

I'm a very goal oriented person. I have a matrix of goals that I keep updated (more or less), with columns for goals in the spiritual, physical, personal, financial, and social areas, and rows for the time frame: one month goals, 3 month goals, goals for the year, for the next 3, 10, and 30 years.

One of the goals I have written down in the spiritual area is to have a close enough relationship with God that, when it comes my time to die, it will be just walking home with my best friend.

But I came to realize some time ago that I had a mistake in this goal. Not that it is a bad goal, but I had it as a 30-year goal. And none of us has any assurance of any given length of time to accomplish it, let alone another 30 years.

So one of the areas that I struggle with regularly is building my relationship with God.

A couple years ago, I studied a book by Gary Moon entitled Falling for God. It's about the topic of developing a relationship with God, and he draws analogies to human relationships. For his purposes, he divides the development of our relationship into 3 phases: Conversation, Communion, and Consummation. I'm still in the first phase. Moon makes the point that you cannot expect to develop a relationship with anyone, God or a human, without spending time with the person, time in conversation.

Like many believers, I'm a firm adherent to the idea of a more-or-less daily "quiet time". Like most believers, I thought of this in terms of time spent in studying the Bible, and in prayer.

But I'm reminded of an episode of a sit-com I saw many, many years ago. I can't remember what show it was, or who the actors were, but the essence of the plot line is something like this. The mother in the story is in the chapel of a hospital, because her son is in ICU, and she is desperately praying for his recovery. This native-American spiritual guru comes in, and strikes up a conversation with her. She tells him about the boy's situation, and how she is pleading with God, bargaining with him, recounting to him what a good boy her son is and how he deserves to be healed. Then the Indian says gently, "Let me get this straight. (Pause) You're carrying on a conversation with the Great Spirit (Pause) and you're (rising inflection) doing all the talking?"

And isn't that how we spend most of our time with God? We talk, talk, talk, telling him what we want or what (we think) we need, asking him to bless OUR plans, asking him for others needs, perhaps even spending time worshipping him and thanking him. And we certainly should be doing these things. But is that how we get to KNOW God? If you were always doing all the talking to a friend, and never listening, how would you get to know him or her? So, I have purposed to spend more time trying to listen to God.

The problem, of course, is that we're not used to hearing God talk the way we here a friend talk. We are taught that Christianity is a relationship with God, but when it comes to developing that relationship, there are very few voices raised to indicate that we can actually here from God personally. One that I have encountered is John Eldredge. He devotes his most recent book, Walking With God (sub-titled "Talk to Him. Hear from Him. Really.") to expounding the idea that "We are made for intimacy with God. He wants intimacy with us. That intimacy requires communication. God speaks to his people." (p. 16).

But, for me (and I don't think I'm alone), listening for God to speak is very frustrating, because, listen though I might, I hear his voice very seldom, or at least I don't hear it clearly. I don't know if this is because he is not speaking to me, or because I haven't yet learned how to listen. Moon's book (referred to earlier) is about learning to listen, by spending enough time quieting ourselves to give ourselves a chance to hear his voice. This is what has been referred to as the Christian discipline of meditation, or what some have referred to a "contemplative prayer." But I find that, while I may spend as much as an hour trying to quiet myself and hear God's voice, if I can get as much as 60 seconds without distracting thoughts that would totally obliterate God's voice, then I think I'm doing good.

But I find I'm not alone at this. Henri Nouwen, who, according to my understanding, is viewed by many as one of the foremost authorities in this area, says " 'Why should I spend an hour in prayer when I do nothing during that time but think about people I am angry with, people who are angry with me, books I should read and books I should write, and thousands of other silly things that happen to grab my mind for a moment?' Nouwen posed that question in different forms, toying with different answers. Sometimes he fell back on the need for spiritual discipline, for being faithful even with no apparent reward… In the end, Nouwen concluded that 'sitting in the presence of God for one hour each morning – day after day, week after week, and month after month in total confusion and with a myriad of distractions – radically changes my life.' " (Henri Nouwen, Primacy of the Heart, quoted by Philip Yancey in Prayer, p. 153)

And so I muddle on.


Sunday, December 14, 2008

Some of my friends











The pictures posted here are from a get together at a ranch in rural Grayson county. It's a bunch of guys that I have become very close to as we have met together over the last 3 months or so and shared with one another our lives and struggles as we seek discover and grow the strengths that we each possess as men. The pictures are from one aspect of the weekend, shooting skeet. The real point to the weekend was to be able to spend time with other men, talking, eating together, and sharing our lives.)