Blog Spam

I hate blog spam.  I have been getting a lot of it.  I am upgrading to BlogEngine.NET 1.6 and we'll see if that takes care of it.

Tags:

finally fixed my email

For anybody who tried to contact me via my blog, I haven't gotten any messages. I just discovered I had a bad smtp server.  OOPS!

Tags:

SourceSafe on it's way out!

I haven't used VSS since 2007, but good to see an "end of life" plan being developed to finally get developers off it.  The problem I've seen before is that TFS just plain costs too much.  This drives people to other solutions like Subversion and Git

http://tech.yahoo.com/news/infoworld/20090930/tc_infoworld/93983_1

Tags:

General

Product cross sells using Linq to SQL

Ok, so finally I have an e-commerce related post.  Tonight I was adding cross-sells to my site.  The concept is simple - when displaying a product, at the bottom of the product page, list products that might also be of interest to the shopper.  To facilitate this, you'll need a Cross Sell table:

This table just contains two product id's.  One is the product Id of the item the shopper is currently viewing, the other is the product Id of the product that you want to cross sell.  So all you have to do is make a call out to your database by passing your product Id and return one or more products that you want to cross sell.  Then display them.

In the past, I would have written a stored procedure to retrieve the data.  Something like this: 

But I'm moving away from stored procs in this new e-commerce site I'm working on, and using Linq to Sql.  I have written hundreds on basic linq queries, but how do you accomplish this task?  I have a select embedded inside a select.  Well, here is the solution:

First grab your Cross Sell records and store them in a var called crossSells.  Then create another query from your Products table, join to manufacturers (to get the manuf. name for dispay purposes), and set the where to get those items from crossSells that contain your productId.  No matter how many "queries" you construct, only one SQL statement is executed.   Your var is an IQueryable and you can embed these inside others.  Very cool and very easy to get straight in your head when you seperate them. 

 

 

Your SQL query isn't actually constructed and run until you enumerate over it (call .ToList() for example).  In the above code, I want to return a generic list of Product objects. So, after creating my two linq statements, I return products.ToList();

The SQL that is created can be easily seen.  Just set a breakpoint on the return statement and look products. 

There you have it.  Move away from stored procedures and into the cool world on Linq to SQL (or Linq to Entities).

Thanks to Rob Conery's blog for this information.

Tags:

e-commerce

Making table changes in SQL Server 2008

This is more of a note to myself.  Every time I reinstall SQL 2008 and want to make a table change, I am faced with this error: 

Nice warning, but please, just let me make changes to my tables.  I'm trying to develop here.  Now I understand this is good for a production environment in case you are making a quick change to a table (I would use RedGate's tools myself though).

To fix this, in SSMS, go into the Tools menu, choose Options.  Then click on Designers in the treevier.  Uncheck "Prevent saving changes that require table re-creation".  There you have it. 

Again, I have forgotten about this setting a dozen times.  Hope it helps someone.

Tags:

Silverlight 3 Pros and Cons

great post by Dan Wahlin here on the pros and cons of SL3 developement.  I have been wanting to blog more on my experiences in e-commerce development but am struggling to find time.  I'm a one man shop at the moment!  Work on my new ASP.NET site is coming along nicely.  I have a professional UI in place now, just tidying up the paging and completing the checkout process.  Once that is finished, It's back to my SL3 administration application.  Silverlight is such a great platform and it's really going to allow my customers to efficiently manage their store. 

More blogging to come...

Tags:

e-commerce

AG_E_PARSER_BAD_PROPERTY_VALUE

Why in Silverlight 3 do I still get these cryptic error messages?  This happens quite frequently to me.  I do a lot of copy/paste between my user controls in Blend or Visual Studio.  Take a look at this XAML for a Button: 

<Button x:Name="btnSave" HorizontalAlignment="Right" Margin="5" Content="Save" Grid.Column="3" Grid.Row="20" Click="btnSave_Click" />

I just copied this from another user control onto a new user control.  It just happens to contain a handler for the Click event, "btnSave_Click".  Well if you forget to create the event handler for it in your new control, you end up with the cryptic

To fix, go back to your XAML, right click on this:

Click="btnSave_Click"

and choose "Navigate to Event Handler".  This will create a stub method for you and you can continue on.

Why in a V3 release are we still not helping developers along?  Yeah, I goofed by just doing a copy/paste without also creating the event handler, but why isn't VS smart enough to tell me this?

Tags:

Good tutorial for Silverlight with WCF and Linq To Sql

Part of Jeff Blankenburg's "31 Days of Silveright".  I went through this tutorial to get myself refreshed on Silveright.  It's been about 6 months since I've done a SL2 project and needed refreshing.

http://jeffblankenburg.com/2009/07/day-7-using-wcf-web-services-with.aspx

 

Tags: , ,

Silveright and WCF on Windows 7 issues

I've just found a solution to a problem I was having.  Using SL2 when adding a service reference to my WCF service, my project compiles fine, but does not run.  I get the error:

"Unrecognized element '' in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight."

It turns out this is only a problem on Windows 7 rc. In your client side service reference file, something like MyServiceReference.ClientConfig, you'll have:

The fix is to remove the <security> element above that is circled.  Apparently this is not valid and only happens on Windows 7 RC.

Tags: , ,

General

Linq to Sql connection strings in a class library

So after writing the last post, I thought my SQL connection problems were solved.  After all, I could remotely connect to my server through SSMS, but then when I actually tried to connect through my asp.net web application, I got the dreaded:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) "

I googled and messed around with my new server for 6 hours.  I got so desperate to figure out why I couldn't connect to my new server that I signed up for some cheapie SQL 2008 hosting, attached my database, and tried to connect to that one.  Same exact issue.  I had played around with IIS security, file and folder security, SQL permissions, asp.net permissions, but nothing worked.  I read the message....it says it can't find my server..hmm..  So I set a breakpoint in my code and ran in debug mode.  I looked at the datacontext and bingo!!!  I don't know why I hadn't thought of this earlier.  I have three seperate class libraries in my web app that use Linq to Sql.  I never pay attention to how it actually works, I just drag on my tables and go.  But I discovered that it was using a connection string that was located in my application settings file that was NOT the correct connection string!  It was using the connection that I set up during development.  So obviously I need to change the connection string, but what a pain that would be.  Seems like there should be a better way.  After all, you need to move your site through development, testing, staging, and production, so you would need to change these connections.

Well, here is the trick:

1.  Open up your dbml designer and look in the properties windows.  Expand Connection.  Change Application Settings to "False". 

2.  Next to Connection select "(None)" from the drop down.  This will clear out the connection string that was being used from your Application Settings.  You can delete the Settings.cs file under Properties too now and also the App.Config.

3.  If you compile, you'll get errors.  This is because you need to somewhere pass in a connection string.   To do this, create a partial class in your class library.  

In this class, you are pointing to a connection string that is located in your web.config file.

That's it.  Do this for all your class library projects and they will all point to a single web.config located in your web project.   I must give credit to Rick Strahl, whose blog I read regulaly.  He got me thinking about Linq to SQL and connection string when reading his blog this afternoon.  Much headbanging and pulling my hair out and it was something as simple as trying to connect to the wrong server!   I really hope this helps someone.

Tags: