Wednesday, June 17, 2009

Cross Apply Incorrect syntax near '.'

I recently ran into an issue that had me puzzled for a bit.
I was using the new Cross Apply functionality in SQL 2005 and was getting the error:

Incorrect syntax near '.'

I checked and rechecked my syntax but couldn't figure out what I had done wrong.
After doing some googling I came accross this sqlteam post in which another poor guy had worked through the same issue.
He ended up figuring out that Cross Apply didn't work when the database was set to sql 2000 compatibility. It makes sense, though it might have been nice to get a more clear error message.

Armed with that information I looked up the code to change the db compatibility level, and what do you know my problem was solved.

Here is the code copied from the link above:
----SQL Server 2005 database compatible level to SQL Server 2000
EXEC sp_dbcmptlevel AdventureWorks, 80;
GO
----SQL Server 2000 database compatible level to SQL Server 2005
EXEC sp_dbcmptlevel AdventureWorks, 90;
GO

Monday, June 8, 2009

Colorado Technical University

I was recently reading on military.com and discovered that Colorado Technical University was one of their recommended colledges.
It seemed they favored CTU because the college not only had higher education courses and has a great distance educational program but also because the school takes special care to tailor itself to the service man/woman's needs. For example they allow the service member to put their education on temporary hold if they get deployed.


Getting such praise from the military is great for me since that just happens to be the college I graduated from. Now that I have joined the U.S. Army, when I want to continue my education I won't have any issue transfering education since they already have all my records.

Web Resource but no Embedded Resource

I was having a major problem trying to get an embedded javascript file registered.
The issue started because I was trying to port over Raj Kaimal's ( http://weblogs.asp.net/rajbk/ ) GridView client side reordering extender to the Data Grid. Since both controls are very similar the work wasn't difficult, however I was getting hung up trying to stick the .js file in my backend dll.

Searching google it seemed as though a lot of people got hung up in this area. I finally stumbed on Lee's post which directed me to Damian's blog

While niether of those posts directly solved my issue, Damian gave me the idea of using a reflector to see what the .NET view of my dll looked like. From that and a little luck I discovered that the proper syntax was:
[assembly: System.Web.UI.WebResource("[default namespace].[folder].[file name].js", "text/javascript")]

then for the script reference:
new ScriptReference("[default namespace].[folder].[file name].js", "[assembly name]");

most people keep the default namespace and the assembly name the same which makes things simpler but fosters a lot of confusion as to what the various parameters are really looking for.


Wednesday, March 25, 2009

T-Sql trigger doesn't always work.

I'm having a rather odd problem.  A trigger I wrote for database Inserts seems to work about 99 percent of the time, but periodically some records will get inserted that the trigger never fires for.  Or rather that the data the trigger is suppose to create is never created.

It's a rather odd delima, if I can figure it out I will try and put the answer here.  In the meantime, if anyone else has experienced this I wouldn't mind hearing about it.

Ok I figured out the answer with a little help from Google.
turns out that in SQL Server a trigger fires once per set of operation as opposed to once per affected row.
so for a standard insert statement the trigger works fine, but if the insert statement has more than one record it is inserting then the trigger will only be fired once.  Good news is that the "inserted" table contains all the records that were inserted, not just one; so you still have access to all the records, you just get them in batch form instead of individually.

Monday, March 2, 2009

Unwanted space between li elements in IE

I ran into an old problem today... a problem where some extra white space was appearing between items in a list.
In this particular case it was only appearing below list elements in an ul where the li contained an image.
Caused the problem:
<ul>
<li><img src="submenu.gif" /></li>
<li>Contact Us</li>
</ul>

Fixed the problem:
<ul>
<li><img src="submenu.gif" />& nbsp;</li>
<li>Contact Us</li>
</ul>

To fix the issue I ended up manually adding a space with the html code & nbsp;
I recall this issue occuring with some floated divs in IE6 as well, though this time I was having the issue with IE7.

It's a really odd fix to a bug in IE7, but it does seem to work and doesn't seem to cause adverse affects in other browsers.

Wednesday, February 18, 2009

Getting and Setting cookies

I was recently having a lot of trouble trying to set and read a cookie in asp.net.  I discovered that my big issue was not correctly using the Request and Response objects.  The Request object is only used for retrieving a cookie, while the Response object is only used for creating a cookie.

Another little anomaly I found.  Apparently the client doesn't send the experation date of a cookie when it sends the cookie to the server.  So, in asp.net when retrieving a cooky the experation date will always be MinDate even if the date is set correctly.

    HttpRequest oRequest = System.Web.HttpContext.Current.Request;
    HttpResponse oResponse = System.Web.HttpContext.Current.Response;

      HttpCookie oCookie = oRequest.Cookies[ConfigurationManager.AppSettings["anonUserCookie"]];
      if (oCookie == null) oCookie = new HttpCookie(ConfigurationManager.AppSettings["anonUserCookie"], Guid.NewGuid().ToString());
      oCookie.Expires = DateTime.UtcNow.AddMonths(1);
      oResponse.Cookies.Add(oCookie);

Monday, February 16, 2009

IE7 div centering with margin auto

I've been having some problems getting a div to center on a webpage.  All the websites I have visited said the fix was easy and gave me various forms of this as a solution:

<div style="text-align:center;">
<div style="text-align:left;">
Content goes here.
</div>
</div>


However, no matter what I put in my stylesheet I couldn't get it to work.  Turns out this fix has to be applied inline.  Putting it in a stylesheet doesn't work.  Once I got that figured out and grumbled for a bit everything worked great.