Mike Taulty's Blog
Bits and Bytes from Microsoft UK

Browse by Tags

Blogs

Mike Taulty's Blog

Elsewhere

  • 13th May – Session at the SQL Servers User’s Group at Microsoft, Reading

    Just a quick plug – tomorrow evening I’m doing a session on ADO.NET Data Services (“Astoria”) at the SQL Server User’s Group at Microsoft, Reading. See here for details; http://sqlserverfaq.com/events/167/Sessions-on-Understanding-ADONET-Data-Services-Windows-7-features-indepth-and-the-usual-SQL-Nuggets-and-Networking.aspx it’d be great to see you there.
  • Virtual Earth & SQL Server Event – London, April 16th

    Johannes Kerbeck and Simon Sabin are running an event around Virtual Earth in the Microsoft offices in London on April 16th. Sounds like an interesting take on things to me is that it seems to be angled more around taking spatial data and applying it in both places. More details from here . You won’t see me there though. I’ll be here .
  • ADO.NET Data Services Session at SQL Bits Manchester

    A big thanks to all the people who came along to my session at SQLBits today on ADO.NET Data Services and also to the organisers and community around SQLBits that made the event happen in the first place. I was there for most of the afternoon and it seemed like a fantastic event to me in a cool venue. As promised, my slides from the session are here for download – you’ll perhaps notice that there are a few additional (hidden) slides in the slide-deck that I didn’t use in this talk as I collapsed this talk down from an earlier talk and updated it to reflect the RTM version of Data Services and also the various CTPs/Previews that are currently kicking around. So…you get a little more than I actually used at the conference. Enjoy :-)
  • Astoria Online/Offline

    Tantalising post from the Astoria team.
  • DataGrid - Master/Details

    Following on from that previous post about the WPF DataGrid I thought it might be interesting to try and move towards more of a master/details view with a separate grid displaying the orders for each customer. I modified the UI a little bit; < Window x:Class ="BlogPost.Window1" xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" Title ="Window1" Height ="600" Width ="800" xmlns:grid ="http://schemas.microsoft.com/wpf/2008/toolkit" > < Grid > < Grid.Resources > < Style x:Key ="myStyle" TargetType ="{x:Type Control}" > < Setter Property ="Margin" Value ="10" /> < Setter Property ="FontSize" Value ="16" /> </ Style > </ Grid.Resources > < Grid.RowDefinitions > < RowDefinition Height ="Auto" /> < RowDefinition Height ="2*" /> < RowDefinition Height ="2*" /> < RowDefinition Height ="Auto" /> </ Grid.RowDefinitions > < TextBox x:Name ="txtCountry" Style ="{StaticResource...
    Filed under: , , ,
  • Messing with Dynamic LINQ Queries

    Mike was chatting to me about how you'd take something like this ( against LINQ to SQL and the Northwind database ); using (NorthwindDataContext ctx = new NorthwindDataContext() { Log = Console.Out }) { string [] values = { "A" , "B" , "C" }; var query = from c in ctx.Customers select c; foreach ( string s in values) { string t = s; // Care to avoid capturing the same value 3 times... query = query.Where(c => c.CompanyName.Contains(t)); } query.ToList(); } Console.ReadLine(); which produces; SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun try], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE ([t0].[CompanyName] LIKE @p0) AND ([t0].[CompanyName] LIKE @p1) AND ([t0]. [CompanyName] LIKE @p2) -- @p0: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%C%] -- @p1: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%B%] -- @p2: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%A%] and write a new...
    Filed under: , , ,
  • SQL 2008, Filestream, Docs from VB

    Someone asked me if I had a simple sample of how to read/write documents into a database table using FILESTREAM in SQL Server 2008. I set about it. Firstly, I had to find out how to switch FILESTREAM on in the RTM of SQL Server. At times like this you need Bob Beauchemin to tell you how it's done and then you can go and run code such as this once you've done the necessary bits in SQL Configuration manager; exec sp_configure filestream_access_level, 2 reconfigure go CREATE DATABASE Documents ON PRIMARY ( NAME = DocData, FILENAME = 'c:\temp\docs.mdf' ), FILEGROUP FileGroup CONTAINS FILESTREAM ( NAME = DocFiles, FILENAME = 'c:\temp\docstreams' ) LOG ON ( NAME = DocLog, FILENAME = 'c:\temp\docs.ldf' ) GO and now I've got a database that can accept file stream data. Phew. Time for a simple table; create table Docs ( id uniqueidentifier rowguidcol not null primary key , documentData varbinary( max ) filestream not null , documentName nvarchar(1024) not null ) Now I've got a table I can use something like Windows Presentation...
    Filed under: , , , ,
  • On LINQ to SQL, Concurrency and Timestamps

    I came across a bit of a glitch in using timestamps for checking concurrency violations in LINQ to SQL and thought I'd share. Say I've got a table like; create table Person ( id int identity primary key , firstName nvarchar(30), lastName nvarchar(30), timestamp ) so, we have a simple table that has a timestamp on it and I want to use that to detect any concurrency problems that I might have in LINQ to SQL. Let's populate this table with some data; insert person(firstname,lastname) values( 'first1' , 'last1' ) insert person(firstname,lastname) values( 'first2' , 'last2' ) insert person(firstname,lastname) values( 'first3' , 'last3' ) and then I can bring that into my LINQ to SQL environment and I can check what the concurrency options are set to; So, you can see that we've got Update Check set to Always and that means that the timestamp will be added to any where clauses for Deletes or Updates and if a particular update doesn't find any row to update because of that where clause then we have a concurrency violation...
  • Michael Rys in London on Non-Relational Data in SQL Server

    The UK, SQL Server User Group has Michael Rys delivering a talk on Monday in London. Michael's a Program Manager in SQL Server. Go here for the details and to sign up. I don't know Michael personally but I know that back when I was looking at SQL Server 2005 and I asked any kind of question about the new XML data type it was more-often-than-not an email that came back from Michael with the answer in it so you should be in for a treat if you manage to get yourself signed up for this.
  • "When Do Queries Execute"

    Julie's got a great post about when stored procedures execute when using LINQ to Entities . It made me think about LINQ to SQL where if I've got something like; using (NorthwindDataContext ctx = new NorthwindDataContext()) { var query = ctx.GetCustomersByCountry( "UK" ); // SQL Happens Here! foreach (Customer c in query) { Console.WriteLine(c.CustomerID ); } } Then we see the same effect as Julie's seeing in LINQ to Entities (note GetCustomersByCountry is a stored procedure) whereas if I've got something like; using (NorthwindDataContext ctx = new NorthwindDataContext()) { var query = ctx.FnGetCustomersByCountry( "UK" ); foreach (Customer c in query) // SQL Happens Here { Console.WriteLine(c.CustomerID ); } } where FnGetCustomersByCountry is a table-valued function then the query is executed at a different point in time. I guess one reason for this is that table-valued functions are composable in LINQ to SQL so I can do something like; using (NorthwindDataContext ctx = new NorthwindDataContext()) { var query ...
    Filed under: , ,
  • Mocking LINQ to SQL

    Matt Warren has an "interesting" post on how you could hack your way to a mocked implementation of LINQ to SQL - if I had a pound for every time someone's asked me how to do this then I'd have at least 3 pounds :-) Seriously though, there is interest in doing this kind of thing and it's a good starting place if you're inclined to head down this route.
    Filed under: ,
  • LINQ to SQL and SqlConnection ( "when you're wrong, you're wrong" :-) )

    I was talking to Ian and another chap at the UK Launch yesterday about LINQ to SQL and my use of the DataContext in some demo code where I always tend to write something like; using (DataContext ctx = new DataContext()) { } and whether I actually needed to do that dispose or not? Now...I was pretty confident that I do need to do this for two reasons; DataContext is disposable so I figure I should probably Dispose() of it - generally been my approach to anything IDisposable. Someone had recently asked me whether DataContext.Dispose() actually did close the SQL connection and I'd done a little bit of reflecting on it and spotted that; DataContext.Dispose() -> SqlProvider.Dispose() -> SqlConnectionManager.DisposeConnection() -> SqlConnection.Close() although the code paths are more complex than that and I haven't attempted to figure out under what conditions the various calls happen. So, I'd kind of reasoned that; If you don't dispose of the DataContext then you won't get the connection closed and back in...
    Filed under: ,
  • LINQ to SQL, Stored Procs, Output Params, Readers Reading

    I had a discussion at DevWeek about when SqlDataReader.Read () gets called for resultsets coming back from stored procedures accessed with LINQ to SQL. I've got this stored proc; create procedure dbo.GetCustomersByCountry @country nvarchar( max ) as set nocount on select * from dbo.customers where country = @country and I've brought it into LINQ to SQL using the designer and that means that I can write code such as; using (NorthwindModelDataContext ctx = new NorthwindModelDataContext()) { var query = ctx.GetCustomersByCountry( "UK" ); foreach (Customer c in query) { Console.WriteLine(c.CustomerID); } } Question is - when does SqlDataReader.Read() get called here? Do we read all of the data up front and then just provide access to an in-memory collection or is the data read from the wire as the loop iterates over it? I wanted to check so I went ahead and set some breakpoints in a few places; Inside the constructor of my Customer class. Inside SqlDataReader.Read() and what I see there is an interleaved set of calls...
  • ADO.NET Entity Framework - QueryViews, Inline Functions in SSDL

    I have a mail from Tim on the EF team that I've had for a little while. I'd asked a question about mapping and he'd given me an answer saying something like "Oh, you could always do X, Y, Z" and I'd left this mail in my inbox for a while because I've been distracted and also because I didn't really understand how to do X, Y and Z but I didn't really want to say :-) Today, I think I understood a bit more of it and the result is twofold. The first of those folds is that I'm thinking that I'd really like to spend maybe a week in a darkened room doing nothing but Entity Framework but I doubt that I'll get the chance as (strangely) in my job I'm not really encouraged to learn technology but that's another story and not one that I'll bore you with here. The second of those folds is that I really think that the Entity Framework still has a whole lot of documentation and explanation that's going to be needed if people are really going to get it - there's a lot in there and it's not immediately obvious how to use it and...
  • SQLBits - Birmingham, 1st March

    Just a quick plug :-) I'm speaking at the "SQLBits" conference in Birmingham on the 1st March. The agenda is up here . The agenda is built by voting from prospective attendees and I found it interesting in that I submitted a few sessions that looked something like; "Entity Framework Tour" "LINQ to SQL" Tour "LINQ to Entities" Tour (this is similar to the first topic but with a very different emphasis) "Understanding LINQ" and what surprised me is that the last session was the one that got picked despite it being the session that I'd say is least directly related to SQL - i.e. you can quite happily have some LINQ without bothering with a relational database. So...if you can make the date and the location then sign up for SQL Bits and I look forward to seeing you at my session if it appeals to you. As an aside, if there's something that you'd like to see included in a session like "Understanding LINQ in .NET Framework V3.5 and Beyond" then feel free to ping me a mail letting me know what it is that you want to see...
    Filed under: ,