Monthly Archives: June 2007 - Page 2

Creating Packaged ASP.NET Setup Programs with VS 2005

Great article by Scott Guthrie in which he describes how we can create packaged ASP.NET Setup Programs with VS 2005:

Scenario

You have built an ASP.NET Web Application using Visual Studio 2005, and want to enable customers to automatically install and deploy it on servers via an easy setup program.

Specifically, you want to create a standard Windows setup program that will create and configure the application on IIS, copy all of the application’s files to the appropriate location on the server, and ensure that ASP.NET 2.0 is correctly mapped to run the application. You also want the setup program to prompt the customer for the database location that the new application should use, and have the setup program automatically update the web.config file with the database connectionstring settings the customer provided.

One solution to consider using is the built-in “Web Setup Project” support that is built-in to Visual Studio 2005. Web Setup Projects can be used to pipe the compilation outputs from VS 2005 Web Application Projects as well as Web Site Projects (when used with VS 2005 Web Deployment Projects), to create encapsulated Windows setup programs. The below walkthrough demonstrates step-by-step how to create and use one.
read original

Firefox 3: SQLite and more

The guys at ajaxian.com have new interesting post describing the new features in the last Firefox Alpha 5 release. Check it out here:

Firefox 3 is to support SQLite for offline storage. The new alpha release tells us this and a lot more (below).

The world of the RDBMS has come to the browser, and has jumped from server to client in the Web platform.

  • Bookmarks portion of Places has been enabled
  • New crash reporting system, Breakpad. It’s
    enabled by default on Mac OS X, on about 50% of Windows installations, and not yet available on Linux.
    You can also view crash reports at this site.
  • New Javascript-based Password Manager. More details available here.
  • Support for Growl notification under Mac OS X
  • Support for native controls on Mac OS X
  • Miscellaneous Gecko 1.9 bug fixes

read original

ASP.NET Master Pages Tips and Tricks

Really nice article by Dan Wahlin in which he writes about ASP.NET Master Pages Tips and Tricks. Here is part of it:

With the release of ASP.NET 2.0, developers were given a simple and effective way to apply a consistent layout across multiple pages in a website. By creating a file with a .master extension that defined a website’s overall layout template and referencing it with the Page directive’s MasterPageFile attribute, website development and maintenance took a step forward in the direction of greater productivity.

Master pages have been around for over one and a half years, so I won’t cover the fundamentals of creating and using them, as many tutorials and books have already been written about the topic. Instead, I’ll focus on a few tips and tricks that can be applied when using master pages. To start, let’s examine how the MasterType directive can be used to reference master page controls in a strongly-typed manner from a content page.

Using the MasterType Directive

Pages that reference controls in a master page, such as a Label in the header, or Menu on the left or right of a website template, typically do so by using the Page class’s Master property along with the FindControl() method, as shown in Figure 1.

Label lbl = this.Master.Page.FindControl("lblHeader") as Label;if (lbl != null){lbl.Text = "Welcome from the content page!";}

Figure 1: controls in a master page can be accessed by using the Master property combined with the FindControl() method.

While this approach certainly works, any misspellings in the quotes will not be caught by the compiler, resulting in a runtime error or a null object reference being returned. Fortunately, a strongly-typed solution is available that doesn’t involve casting the Master property to the base class of the master page in order to access its members (keep in mind that any server controls defined in the master page won’t be accessible even after a cast is performed, because they’re marked as protected by default).

read original

New Weekly Series: Silverlight Video Tutorials

On this page you will find dozens of videos designed for all Silverlight designers and developers, from the novice to the professional.

Video Categories

MIX 2007 Silverlight Sessions

“How Do I?” with Silverlight 1.0

“How Do I?” with Silverlight 1.1

Using Blend with Silverlight 1.0

Safari 3 Public beta Available for Windows

Safari for windows have just been announced today during the Apple WWDC conference. The new Beta is available for download free for Mac, WinXP and Vista, and will make the competition between browsers very aggressive after that IE stopped its development for mac platform. Some interesting performance numbers have been announced on the new Safari home page, according to it :

  • HTML performance: Safari3 2.14 Seconds, FF2 3.67s, IE7 4.63s and Opera9 6.22s
  • JavaScript performance : Safari3 0.88 Seconds, Opera9 0.98s, FF2 1.72s and IE7 2.48s
  • Application launch : Safari3 1.74 Seconds, Opera9 1.82, FF2 2.22s and IE7 2.34s

safari performance thumb Safari 3 Public beta Available for Windows

The tests have been made on a 2.16GHz Intel Core 2 Duo-based iMac system running Windows XP Professional SP2, configured with 1GB of RAM and an ATI Radeon X1600 with 128MB of VRAM. The greatest news for today, it’s just not working correctly on my winxp !

Update: Safari for windows seems to be good only as iPhone validator (for buzz words lovers). Applications running correctly on Safari will work fine on iPhone also according to Steve Jobs. Otherwise better call this a pre-alpha.

read original

New ASP.NET AJAX Control Toolkit Release

Scott is writting about the new ASP.NET Ajax Control Toolkit. Here is his post:

Yesterday the ASP.NET AJAX Control Toolkit team released an updated version. You can download it from the http://ajax.asp.net web-site, and run samples built with it on the online samples page here.

The ASP.NET AJAX Control Toolkit is a free download and contains more than 40 additional AJAX controls and components that work on top of the core ASP.NET AJAX 1.0 release. In addition to having Microsoft developers contribute, the project also has more than 15 non-Microsoft contributors adding great features and controls.

You can download either a binary version of the ASP.NET AJAX Control Toolkit to use (just add to your toolbox and you are good to go), or you can download the source for the project itself and tweak/extend it if you want (all source is released under a permissive license allowing you to make your own modifications to it).

New ToolkitScriptCombiner Support

One of the biggest improvements with this toolkit release is support for a new “ToolkitScriptCombiner” control. This control allows you to replace the default control behavior, and supports the ability to dynamically merge multiple client-side Javascript scripts into a single file that is downloaded to the client at runtime. Better yet, only the Javascript needed by the specific controls on the page are included within the combined download, to make it as small as possible.

The big benefit with this feature is that is can significantly reduce the number of Javascript files the browser needs to download, as well as reduce the overall download size of the scripts. This can provide some really nice performance and load-time wins on pages. Best of all – you don’t need to change any code or refactor any script yourself to take advantage of this.

Other ASP.NET AJAX Control Toolkit Improvements

This week’s release contains a number of other new improvements, including:

  • More than 125 bug fixes
  • Extended client side event support – new client side event handler extensibility points are available with common toolkit server controls
  • ASP.NET Validation Controls now work with the Toolkit Controls
  • Accessibility fixes: Slider and AutoComplete have support for high contrast and other controls have JAWS accessibility support built-in when doing AJAX callbacks.
  • Animation support: More toolkit controls now have generic animation support built-in
  • Nice design mode improvements for the controls, including: 1) designer support for the TabContainer. You can now select/add/remove tabs within the tabcontainer directly from the designer, and you can directly edit both the content and the title, 2) page methods can now automatically be generated for those extender controls that call web-services, 3) nice icon support within the toolbox.

You can learn more about all of the improvements in blog posts from Shawn, David, Kirti and Garbin.

ASP.NET AJAX Control Toolkit Videos

Joe Stagner has been cranking away at recording “How Do I?” videos for the AJAX Control Toolkit, and now has 39 free ASP.NET AJAX “How Do I?” videos hosted on the www.asp.net site.

step2 New ASP.NET AJAX Control Toolkit Release

Click here to watch them for free and learn how to-do common tasks with ASP.NET AJAX and the ASP.NET AJAX Control Toolkit. The most recent videos are now available to download in a variety of video and audio formats, including: WMV, Zune, iPod, PSP, MPEG-4, and 3GP.

ASP.NET AJAX Books

As I mentioned in my links post from last week, the first books specifically targeting the final ASP.NET AJAX 1.0 release were recently published. Below are links to two of them that are shipping today:

step4 New ASP.NET AJAX Control Toolkit Release step3 New ASP.NET AJAX Control Toolkit Release

Both books include a chapter on using the controls within the ASP.NET AJAX Control Toolkit.


read original

What is the difference between VB 9, VBx and Silverlight? (Scott Wisniewski)

Today I came across that post at Visual Basic Team blog which is quite good. Enjoy it reading!
I recently received an email from a customer asking for clarification as to what the difference was between VB 9, VBx and Sliverlight. In particular, it seems as if we have been releasing so much information about cool new stuff that at least a few people have become confused, making them a bit nervous about the future of VB.

The customer had also expressed some concerns about upgrading from VS 2005 to Orcas (VS 2008), particularly because he was considering making an upgrade from VB 6 to VS 2005 and wanted to make sure he would be able to take advantage of Orcas when it was released.

I figured there may be other customers that have similar concerns, and so thought this would make a good blog post, particularly because it’s been a while since I’ve posted anything (J).

As a result I’ve included a few of the questions he asked (paraphrased) below, along with my answers.

I hope this helps.

What is the difference between VB 9 and VBx? Which one is the next version of Visual Studio?

Visual Basic 9 is the next version of Visual Basic. Visual Basic 10, or VBx as it’s sometimes called, is the version of Visual Basic that will follow VB 9. Currently VBx is in very early stages, and is a long way off from production. In fact, most of our development team is actively working on VB 9.

Why on earth would you start talking about VB 10 before you’ve even released VB 9? This is confusing.

The product cycle for VB 9 is starting to wind down. We recently released Beta 1 of Visual Studio Code Name “Orcas”, and are currently working on releasing Beta 2. As the product cycle starts to wind down, our language design team is starting to think about what the “next next” version of the product will look like. They do this mainly as a way to “keep the pipeline moving”. If they had to wait until VB 9 was 100% complete before they started thinking about VB 10, then there would end up being a significant delay from when we finished VB 9 until we could start working on VB 10. This is because designing a product, and coming up with a plan to develop it can be extremely time consuming. It requires us to come up with a design, create a schedule, make any necessary organizational changes, and ensure we have the right staffing levels, all before we start coding. By “overlapping” the early design work for VB 10 with the “end game” work for VB 9 we are able to better “bootstrap” the whole process, thus making the transition from one project to the next as smooth as possible.

As our design team comes up with designs they like to release information about them as early as possible. The earlier we can get information out to our customers, the earlier we can get feedback about the things we are doing. This helps us to build the products that actually meet our customers’ needs. One thing we’ve managed to learn over the years is that the best possible way we can learn what it is that our customers want is to engage with them early and often.

As a result, near the end of a product cycle we will release information about our plans for the version of the product to follow the one we are currently working on. This gives our customers the chance to comment on it and let us know what they think. We then take that feedback and use it to develop a more complete plan for what we want to do.

What is VB 10 going to be like? What is this Silverlight Thing I keep hearing about? Is Silverlight a replacement for Visual Studio?

Our plans for VBx and Silverlight are still very rough and are nowhere near complete. As our customers start to use VB 9 and provide us with feedback that data will drive exactly what we end up doing in VB 10. That being said, however, we do have some rough ideas of the things we would like to do.

Silverlight 1.1 is a new light weight version of the .NET Framework that will allow you to develop rich applications that run in a web browser using .NET languages. The basic idea is to allow you to replace client side java script with .NET enabled languages, allowing you to write both the client side and sever side portions of your web applications in the same language. It also allows you to use WPF (windows presentation foundation) and WCF (windows communication foundation) to create extremely rich and interactive web applications in a way that is much easier than what is possible using HTML, Ajax, Java Script, or Flash.

VB 10 is going to be the version of Visual Basic that will follow VB 9 (the “next next version”). It will include new features designed to make VB a really great language for developing SilverLight apps, as well as enhancements to many of the new feature we are delivering in VB 9, such as Linq. You should still be able to do all the things with VB 10 that you could do with both VB 9 and VB 8.

The migration from VB 6 to VS 2005 is non-trivial. If I upgrade to VS 2005 will I able to use VB 9 when it comes out, or will I have to scrap all my work? What about VB 10? Should I be worried about the future of VB?

The transition from VB 8.0 to VB 9.0 should be smooth and relatively painless. We have gone to great lengths to ensure this.

Our plan is to also make the migration from VB 9 to VB 10 equally painless.

Although the migration from VB 6 to VB.NET is a bit tough, we are actively working on making that easier as well. We have been releasing a “VB Interoperability Toolkit” that allows an application to be gradually migrated from VB 6 to VS 2005, rather than requiring the whole thing to be migrated at once.

You can get more information about it here:

http://msdn2.microsoft.com/en-us/vbasic/aa701257.aspx

As far as the future of VB, you should definitely not be worried.

Microsoft is committed to VB, and making it a great language for developing applications for our various platforms. The future of VB should be a bright one!
read original

Introducing LINQ – Part 5

Introduction

Whenever someone asks me about the DataContext I always refer to it as the “brains” of Linq to SQL, why? Because it is. It is responsible for the translation of Linq to T-SQL, and the mapping of the results (rows) of that query to objects, and so much more.

If you run any codegen tool (SqlMetal, or Linq to SQL file (VS Orcas designer)) you always get a class that derives from the DataContext class. The DataContext can be equated to a database, in that it contains a series of tables (normally this is implemented as a property that returns a Table), and sprocs (methods calls that invoke underlying sprocs at the DB layer).

Note: The DataContext can also handle other SQL Server features like views, and table functions etc.

What’s so special about the DataContext class?

Most notably the DataContext takes some Linq code and generates the appropriate T-SQL statement for that query; if that query returns rows then the DataContext object will take care of mapping those rows to objects.

Figure 5-1: DataContext core functionality

DataContextCorefunctionality Introducing LINQ – Part 5

I want to see the T-SQL generated by my LINQ

If you are a control freak/perfectionist like me then you probably want to know exactly what T-SQL is being generated for you at all times.

Before I show you some code please remember that the T-SQL generation by the DataContext object is not perfect, if you know of a very efficient T-SQL solution then implement that in a sproc. Saying that I have found the T-SQL generation of the DataContext object to be efficient in some advanced queries. Like so many things in programming one way, and one way alone is often not the best approach – experiment to see what offers the best performance for your query.

There are a few ways in which we can monitor the T-SQL being generated by our DataContext object, these include:

  • Visual Studio Orcas
  • ToString() override of query
  • DataContext Log property
  • SQL Server 2005 profiler (not included with Express edition)
Note: As the majority of people reading this article will be using the Express editions of the developer tools I will skip the SQL Server 2005 profiler demo. Those who have used the profiler before will know that it is a real time T-SQL dump of everything that a particular SQL Server 2005 instance is doing so seeing what T-SQL the DataContext is generating is a trivial task.

Visual Studio Orcas

As Linq is a 1st class citizen within the C# and VB.NET languages it should be no surprise to you whatsoever to see rich debugging support within the IDE.

Figure 5-2: Seeing the T-SQL generated by the DataContext object in VS Orcas

DataContextObjectInVSOrcas Introducing LINQ – Part 5

ToString() override

This is a really nice feature – if you call the ToString() method on any variable whose value is a query you can see the associated T-SQL for that query.

Figure 5-3: Calling ToString()

  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace ConsoleApplication4
  5. {
  6. public class Program
  7. {
  8. public static void Main(string[] args)
  9. {
  10. using (BookShopDataContext db = new BookShopDataContext())
  11. {
  12. IEnumerable query = from b in db.Books select b;
  13. Console.WriteLine(query);
  14. }
  15. }
  16. }
  17. }


Figure 5-4: Result of running the code in Figure 5-3

5 4 Introducing LINQ – Part 5

Concurrency

Concurrency is always an issue – Linq to SQL by default uses optimistic concurrency. Take an example of where we retrieve a particular piece of data and then update that data, we then try to submit the updated data to the server but we get an exception as Linq to SQL knows that we have violated a concurrency check as we were acting upon “old” data.

Just to show this I did a pretty simple operation by adding a breakpoint on the line where I call the SubmitChanges(...) method and then executed some T-SQL code to alter that record and then continued the execution of my application so I would get an exception.

Figure 5-6: ChangeConflictException

ChangeConflictException Introducing LINQ – Part 5

The SubmitChanges(...) method is overrided to take a ConflictMode enum where we can change the default behaviour when data is submitted to the database, these are:

  • ContinueOnConflict
  • FailOnFirstConflict

The above can be used when within a TransactionScope. There are a few attribute values we can apply to our generated code to specifically say “we don’t care if this particular bit of data is changed – just overwrite it”. We do this using the UpdateCheck parameter to the Column attribute.

Figure 5-7: We don’t care about this data – just overwrite the value with what we have!

  1. [global::System.Data.Linq.Column(Storage="_Title", Name="Title",
  2. DBType="NVarChar(50) NOT NULL", CanBeNull=false,
  3. UpdateCheck=System.Data.Linq.UpdateCheck.Never)]

The UpdateCheck enum values:

  • Always
  • Never
  • WhenChanged

I’m pretty sure I’ve not covered everything in Linq to SQL with regards to concurrency – remember though that you can use the TransactionScope type in the .NET framework to assist you.

Using VS Orcas to look at data

Remember – queries only execute when we call the GetEnumerator() of the variable that holds the query! In previous CTP’s of VS Orcas it was hard to see what data we pulled back from the database as the debugger didn’t call the GetEnumerator() method when you wanted to look at that particular variable – the March CTP does however which is really great!

Let’s go ahead and look at using VS Orcas to look at data returned from our database using the Locals window when debugging. First place a breakpoint after the line you define a query, you don’t need a foreach to call the GetEnumerator() – the IDE will do that for us. When you get to your breakpoint you will see a screen similar to that in Figure 5-8 where the variable holding our query has a message saying something like “expand me to enumerate this IEnumerable”.

Figure 5-8: Thinking about enumerating the IEnumerable

EnumeratingIEnumerable Introducing LINQ – Part 5

Expand the results! You know you want to.

Figure 5-9: Viewing the results

5 9 Introducing LINQ – Part 5

You can see that in Figure 5-9 I have two objects returned from my query, I can drill down into the values of their properties and so forth.

On the face of it this is a pretty basic enhancement to the IDE, and you would be right in thinking so – but this is a great visual tool which I’m sure you will love when using Linq to SQL!

LINQ to SQL FAQ

Will LINQ to SQL support Oracle?

This is a common question, the answer to which is no. Linq to SQL is a lightweight O/R mapper targeted for use with SQL Server 2000/2005. For a more powerful O/R mapper look at the Entity Data Model (EDM) – EDM will support Oracle and other 3rd party databases.

I hate codegen tools, how much code does it really take to hook up to my DB using LINQ to SQL?

Surprisingly little, essentially you need to create a property with the correct access (get, set, or both?) with the appropriate Column attribute. The class with your properties should be pluralized and use the Table attribute to map it to the corresponding table in the database.

Finally you will need to create a class that derives from DataContext. In this class you will want to expose some properties that return a generic Table.

Below is the code for the TodoListDataContext and Task types:

Task.cs (type that is associated with records in Tasks):

  1. using System;
  2. using System.Data.Linq;
  3. namespace ConsoleApplication5
  4. {
  5. [Table(Name="Tasks")]
  6. public class Task
  7. {
  8. private int _taskId;
  9. [Column(Name = "TaskID", Storage = "_taskId",
  10. IsDBGenerated = true, IsPrimaryKey = true,
  11. CanBeNull = false, DBType = "int not null identity")]
  12. public int TaskID
  13. {
  14. get { return _taskId; }
  15. }
  16. [Column(Name = "Title", CanBeNull = false,
  17. DBType = "nvarchar(50) not null")]
  18. public string Title
  19. {
  20. get;
  21. set;
  22. }
  23. [Column(Name = "Complete", CanBeNull = false)]
  24. public bool Complete
  25. {
  26. get;
  27. set;
  28. }
  29. }
  30. }


TodoListDataContext.cs (type that exposes a Table of type Task, and defines connection string)

  1. using System;
  2. using System.Data.Linq;
  3. namespace ConsoleApplication5
  4. {
  5. public class TodoListDataContext : DataContext
  6. {
  7. public TodoListDataContext(string conn) : base(conn)
  8. {
  9. }
  10. public Table Tasks
  11. {
  12. get { return GetTable(); }
  13. }
  14. }
  15. }


Why are the changes to my data in SQL Server not being persisted?

Remember, in order to persist changes to SQL Server you need to call the SubmitChanges(...) method on your DataContext object after you have made changes to any data.

Can I use XML to define the O/R mapping?

Yes. You can use SqlMetal to generate an XML mapping file, when creating a DataContext you need to specify that your mapping is defined in an XML file by using the XmlMappingSource type.

I’m hitting the database every time for two identical queries, can I prevent this?

To prevent hitting the database every time you can load the results into memory (e.g. Append ToList() to a query) any subsequent calls to that query will use the in-memory collection rather than going off and querying the database again.

Is it possible to create code from XML?

Yes. You can create a .dbml file using SqlMetal and then generate a codefile (either VB.NET or CS) based on the XML defined in the .dbml.

What’s this deferred loading stuff?

Linq to SQL uses deferred loading when accessing properties of a related entity. Given a simple select query returning all Books, if I then want the publisher for each book then I can do so, however, behind the scenes the DataContext is doing a select where query to get the publisher for the current book. This is deferred loading.

Note: You can disable deferred loading using the EnableDeferredLoading property of a DataContext object.

Summary

There is a ton of stuff that’s special about the DataContext that I haven’t covered – I encourage everyone to go check out the DataContext class and experiment. I hope that I have provided you with the knowledge to get started with Linq, and Linq to SQL – if you have any questions about a particular feature of Linq to SQL I have/haven’t covered then please feel free to email me via the address on http://gbarnett.org/about.

read original