Cool SMS/VS2005 Integration Feature

Today I discovered a very wierd feature regarding SQL Management Studio 2005 ("SMS") and Visual Studio 2005 (of course I'm using the FREE standards editions from the MSDN/Technet seminars)

OK so here it is...

  • Open SMS
  • Navigate to a table and modify it.
  • Copy the text of one of the columns
  • Go to an ASPX page in Visual Studio 2005 and paste.

If you did it right you will see the weirdest thing in the world: it pastes a GridView linked to a SqlDataSource, which it also pastes.

<asp:GridView ID="GridView1" runat="server"
     DataSourceID="SqlDataSource2"
     EmptyDataText="There are no data records to display."
     AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="ContactID"
            SortExpression="ContactID"
            HeaderText="ContactID">
        </asp:BoundField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    SelectCommand="SELECT [ContactID] FROM [Employee]"
    ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString1 %>"
    ProviderName="<%$ConnectionStrings:AdventureWorksConnectionString1.ProviderName %>">
</asp:SqlDataSource>

You will also find that it pastes the appropriate connection string directly into your web.config.

<add
 name="AdventureWorksConnectionString1"
 connectionString="[string omitted;  it was LONG"
/>

Cool, huh?

p.s. If you want to paste that particular name, as I wanted to do, you can always do the old school paste-into-notepad-copy-out-of-notepad trick that is a tried and true way to strip off Web Browser formatting.