<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>ADO.NET 2.0</title><link>http://davidhayden.com/blog/dave/category/26.aspx</link><description>ADO.NET 2.0</description><managingEditor>Dave Hayden</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.101</generator><item><dc:creator>Dave Hayden</dc:creator><title>SQLSaturday - SQL Server Data Access Tips and Techniques with David Hayden - Tampa Florida</title><link>http://davidhayden.com/blog/dave/archive/2008/02/10/SQLSaturdaySQLServerDataAccessTipsTechniquesDavidHaydenTampaFlorida.aspx</link><pubDate>Sun, 10 Feb 2008 12:07:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2008/02/10/SQLSaturdaySQLServerDataAccessTipsTechniquesDavidHaydenTampaFlorida.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;SQLSaturday - SQL Server Data Access Tips and Techniques with David Hayden - Tampa Florida&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;, &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Sarasota Web Developer&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.flacodebrew.net/Tag/SQLSaturday.aspx"&gt;&lt;IMG alt=SQLSaturday src="/photos/sql_saturday_logo.jpg" align=right border=0&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;I will be presenting at &lt;/FONT&gt;&lt;A href="http://www.flacodebrew.net/Tag/SQLSaturday.aspx"&gt;&lt;FONT face=Verdana size=2&gt;SQLSaturday&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; in Tampa, Florida on Saturday, February 16, 2008.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here is the abstract:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana size=2&gt;SQL Server Data Access Tips and Techniques&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You have optimized and tuned your SQL Server Database and now you need to access the data from your application. Learn and explore the variety of ways you can access the data using &lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;ADO.NET&lt;/A&gt;, the Data Access Application Block, &lt;A href="http://davidhayden.com/blog/dave/category/59.aspx?Show=All"&gt;LINQ To SQL&lt;/A&gt;, ADO.NET Entity Framework, ADO.NET Data Services, and the &lt;A href="http://davidhayden.com/blog/dave/archive/2008/01/15/ASPNETDynamicDataDisplayingInsertingEditingImagesSQLServerDatabase.aspx"&gt;ASP.NET 3.5 Dynamic Data Framework&lt;/A&gt;. In this session we will walk-thru and build several examples for each technique as well as discuss tips, strengths, and weaknesses. Come with your questions and explore the wonderful world of data access to SQL Server!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;We only have an hour, so I will be prepared to discuss and demo:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET 2.0&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;A href="http://davidhayden.com/blog/dave/category/50.aspx?Show=All"&gt;Enterprise Library&lt;/A&gt; &lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;Data Access Application Block&lt;/A&gt;&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;LINQ To SQL&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Entity Framework&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Data Services&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;ASP.NET Dynamic Data Websites&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This is subject to change, of course, but I thought I would break the presentation into thirds:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;20 minutes: ADO.NET and DAAB&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;20 minutes: LINQ To SQL and ASP.NET Dynamic Data&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;20&amp;nbsp;minutes: &lt;A href="http://davidhayden.com/blog/dave/category/63.aspx"&gt;ADO.NET Entity Framework&lt;/A&gt; and &lt;A href="http://codebetter.com/blogs/david.hayden/archive/2008/01/08/getting-started-with-ado-net-data-services.aspx"&gt;ADO.NET Data Services&lt;/A&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This isn't a deep technical session. It's goal is to expose you to data access options from Microsoft that exist today and are coming down the pike. I&amp;nbsp;will be happy to&amp;nbsp;answer more technical questions after the presentation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;See you there!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Author:&amp;nbsp;&lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;, &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida Web Developer&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Site: &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;http://www.davidhayden.com/&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3455.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Creating Data Access Layer Using DbProviderFactories and DbProviderFactory</title><link>http://davidhayden.com/blog/dave/archive/2007/10/08/CreatingDataAccessLayerUsingDbProviderFactoriesDbProviderFactory.aspx</link><pubDate>Mon, 08 Oct 2007 18:00:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2007/10/08/CreatingDataAccessLayerUsingDbProviderFactoriesDbProviderFactory.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;Creating Data Access Layer Using DbProviderFactories and DbProviderFactory&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida .NET Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ), Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET 2.0&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I know I have mentioned &lt;STRONG&gt;DbProviderFactories&lt;/STRONG&gt; and &lt;STRONG&gt;DbProviderFactory&lt;/STRONG&gt; in ADO.NET 2.0 before, but they were new to some developers this weekend so I thought I would reiterate their use in a database agnostic &lt;A href="http://www.pnpguidance.net/Tag/DataAccessLayer.aspx"&gt;data access layer&lt;/A&gt; in your winform and ASP.NET Web Applications.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;If you look at the connection string in your App.Config or Web.Config:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;add
    name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;ConnectionString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    connectionString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;server=.;Initial Catalog=Northwind;...&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    providerName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;System.Data.SqlClient&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;you will notice the &lt;STRONG&gt;providerName&lt;/STRONG&gt; Property, which represents the unique name for the .NET Framework data provider used to connect to an underlying data source.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;In this case we are connecting to SQL Server, but we don't really need to know that. We can use that providerName to create various connection, command, and other database classes without knowing what type of database we are connecting to by using the &lt;STRONG&gt;DbProviderFactories&lt;/STRONG&gt; and &lt;STRONG&gt;DbProviderFactory&lt;/STRONG&gt; Classes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;First, let's get the actual connectionString and providerName that make up the database we are connecting to using System.Configuration.&lt;STRONG&gt;ConfigurationManager&lt;/STRONG&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    ConfigurationManager.ConnectionStrings
    [&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;ConnectionString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ConnectionString;
    
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; providerName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 
    ConfigurationManager.ConnectionStrings
    [&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;ConnectionString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ProviderName;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Once we have&amp;nbsp;the providerName, we can create a DbProviderFactory class for the database using the DbProviderFactories Class:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;DbProviderFactory provider &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    DbProviderFactories.GetFactory(providerName);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The DbProviderFactory Class exposes several methods that allow us to create classes to access the database:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;CreateConnection()&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;CreateCommand()&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;CreateParameter()&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;CreateDataReader()&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;CreateDataAdapter()&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Again, keep in mind that it does not matter what database we are using at this point - could be &lt;A href="http://davidhayden.com/blog/dave/category/14.aspx?Show=All"&gt;SQL Server&lt;/A&gt;, Oracle, &lt;A href="http://davidhayden.com/blog/dave/archive/2007/01/28/EnterpriseLibraryDAABMicrosoftAccess2007.aspx"&gt;Microsoft Access&lt;/A&gt;, DB2, Firebird, etc. Pick your poison.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Assuming the database supports stored procedures, we can call a stored procedure in a database agnostic way as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (DbConnection cn &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; provider.CreateConnection())
{
    cn.ConnectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (DbCommand command &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; cn.CreateCommand())
    {
        command.CommandText &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;GetAllCustomers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        command.CommandType &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CommandType.StoredProcedure;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;        cn.Open();&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (DbDataReader dr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; command.ExecuteReader())
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Do Something...&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        }
    }
}
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This is an awesome way to target multiple database with your application.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Don't forget you can do some really cool stored procedure parameter discovery as well:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx"&gt;&lt;FONT color=#0000ff&gt;SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - ADO.NET Tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;All good &lt;A href="http://davidhayden.com/blog/dave/category/24.aspx?Show=All"&gt;O/R Mappers&lt;/A&gt; and &lt;A href="http://davidhayden.com/blog/dave/category/15.aspx?Show=All"&gt;Code Generators for the Data Access Layer&lt;/A&gt; handle all of this data access layer database agnostic code for you, but it is still good to know what is happening behind the scenes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Hope this helps!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Similar ADO.NET Tutorials&lt;/FONT&gt;&lt;/H2&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/03/29/2895.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;GetSchema and DbProviderFactories - List of Tables in a Database&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/10/01/GetListOfTablesInMicrosoftAccessUsingGetSchema.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Get List of Tables in an Access Database - ADO.NET Tutorials&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2005/10/30/2550.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;.NET 2.0 Provider Model - Polymorphism - Factory Method - ADO.NET 2.0 Data Providers&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/04/14/2915.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Finding Database Servers / SQL Server Instances on Local Network - GetDataSources - DbDataSourceEnumerator&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/04/01/2898.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Data Access Application Block - Reduce ADO.NET Code in Your Applications&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida .NET Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ), Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET 2.0&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3358.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>ADO.NET Entity Framework - When To Use It vs. Linq to SQL</title><link>http://davidhayden.com/blog/dave/archive/2007/04/29/ADONETEntityFrameworkWhenToUseItVsLinqToSQL.aspx</link><pubDate>Sun, 29 Apr 2007 23:30:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2007/04/29/ADONETEntityFrameworkWhenToUseItVsLinqToSQL.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;ADO.NET Entity Framework - When To Use It&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida ASP.NET C# SQL Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I mentioned earlier that the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/04/29/ADONETEntityFrameworkCutVisualStudioOrcas.aspx"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Entity Framework was Cut From .NET 3.5 and Visual Studio Orcas&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; and we will have to wait until the first half of 2008 to see a release. In the meantime there is &lt;STRONG&gt;Linq to SQL&lt;/STRONG&gt; which I have played with quite a bit and enjoy for &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/24.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;O/R Mapping&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;. I showed a trivial example of it not too long ago:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/03/18/LinqToSqlTutorialSQLServerDatabase.aspx"&gt;&lt;FONT face=Verdana size=2&gt;Linq to SQL Example Tutorial - Visual Studio ORCAS March 2007 CTP - ASP.NET&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Right after the announcement that the ADO.NET Entity Framework was cut from .NET 3.5, the data access team at Microsoft came out with their strategy for data access that is worth reading &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/data/archive/2007/04/28/microsoft-s-data-access-strategy.aspx" target=_blank&gt;&lt;FONT face=Verdana size=2&gt;here&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I really liked the part that discusses when to use the ADO.NET Entity Framework which I cut and pasted below. Most of it is about the ability to define Client Views on existing database schemas so that you can work with the data logically in the client application as opposed to being limited by the database schema. This is a great feature and one I was really looking forward to.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Anyway, here is when to use the ADO Entity Framework according to Microsoft:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;#8220;If you are writing an application that requires any of the following features, you should use the ADO.NET Entity Framework: &lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;The ability to define more flexible mapping to existing relational schema, for example:&lt;/FONT&gt;&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Mapping a single class to multiple tables&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Mapping to different types of inheritance&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Directly Modeling Many to Many relationships&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Mapping to an arbitrary query against the store&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;The ability to query relational stores other than the Microsoft SQL Server family of products.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;The ability to share a model across Replication, Reporting Services, BI, Integration Services, etc.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;A full textual query language&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;The ability to query a conceptual model without materializing results as objects&amp;#8221;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;In the post mentioned above, Linq to SQL is portrayed as more of a rapid development approach for simple projects where the database schema is the domain model and you are using SQL Server. Fair enough. I need that, too :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Source:&amp;nbsp;&lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida ASP.NET C# SQL Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3209.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>ADO.NET Entity Framework Cut From .NET 3.5 and Visual Studio Orcas</title><link>http://davidhayden.com/blog/dave/archive/2007/04/29/ADONETEntityFrameworkCutVisualStudioOrcas.aspx</link><pubDate>Sun, 29 Apr 2007 10:31:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2007/04/29/ADONETEntityFrameworkCutVisualStudioOrcas.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;ADO.NET Entity Framework Cut From .NET 3.5 and Visual Studio Orcas&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Sarasota Web Design&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The recent&amp;nbsp;&lt;A href="http://blogs.msdn.com/adonet/archive/2007/04/28/ado-net-entity-framework-update.aspx" target=_blank&gt;announcement&lt;/A&gt; about the ADO.NET Entity Framework being &lt;STRONG&gt;&lt;U&gt;cut&lt;/U&gt;&lt;/STRONG&gt; from .NET 3.5 and Visual Studio Orcas and instead being shipped during the first half of 2008 has me bewildered this morning. &lt;A href="http://weblogs.asp.net/fbouma/archive/2007/04/29/ado-net-entity-framework-cut-from-net-3-5-orcas.aspx" target=_blank&gt;Frans speculates&lt;/A&gt; on the decision. I am just disappointed with Microsoft's abililty to deliver solutions as promised, on-time, and with&amp;nbsp;timely maintenance releases and service packs.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;News Feed: &lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Sarasota Web Design&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3207.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings</title><link>http://davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx</link><pubDate>Thu, 22 Feb 2007 20:31:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;A href="http://www.davidhayden.com/"&gt;David Hayden&lt;/A&gt; ( &lt;A href="http://www.davidhayden.com/"&gt;Sarasota Web Design&lt;/A&gt; ), Filed: &lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;ADO.NET 2.0&lt;/A&gt;, &lt;A href="http://davidhayden.com/blog/dave/category/60.aspx?Show=All"&gt;Enterprise Library&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Someone asked a question in the forums about how to list all the connection strings located in the app.config or web.config so&amp;nbsp;he could populate a control that would allow the user to choose the active connection at run-time. The person also was using the &lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;Enterprise Library Data Access Application Block&lt;/A&gt; and wanted to know how to find the name of the default connection string.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Both good questions. Let's start with the easy one first.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Reading Default Connection String Name in DAAB Configuration Settings&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;It is very easy to read the default connection string name used by the Enterprise Library Data Access Application Block. There are many ways to do it, but this is the simplest in my opinion if you use the application's web.config or app.config file to store your DAAB Settings:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;DatabaseSettings settings &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;= &lt;BR&gt;  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;DatabaseSettings.GetDatabaseSettings&lt;BR&gt;       (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SystemConfigurationSource());&lt;BR&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; defaultConnectionStringName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;settings.DefaultDatabase;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There is a &lt;STRONG&gt;DatabaseSettings&lt;/STRONG&gt; Class that you can call &lt;STRONG&gt;GetDatabaseSettings&lt;/STRONG&gt; on to get the name of the default connection string. Pass it the &lt;STRONG&gt;IConfigurationSource&lt;/STRONG&gt; where the settings are located. Use &lt;STRONG&gt;SystemConfigurationSource&lt;/STRONG&gt; for the application's app.config or web.config.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Reading All Connection Strings in App.Config or Web.Config&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Actually, reading all the connection strings in the app.config or web.config is pretty easy now that we have the wonderful &lt;STRONG&gt;System.Configuration&lt;/STRONG&gt; Namespace and its rich functionality. The code is pretty straight forward. We can read all the connection strings as well as each name, provider, etc:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;ConnectionStringSettingsCollection connectionStrings &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;ConfigurationManager.ConnectionStrings;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (ConnectionStringSettings connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionStrings)
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionStringName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection.Name;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection.ConnectionString;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; providerName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection.ProviderName;

    Debug.Print(connectionStringName);
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Rather than just printing the connection string name to the output window, you could of course populate a control and allow the user to select one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Based on the name of the connection string the user selects, you can use the Enterprise Library DAAB to access the database:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;Database database &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;   &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;DatabaseFactory.CreateDatabase(connectionStringName);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;If you don't want to use the DAAB, no problem. Use the &lt;A href="http://davidhayden.com/blog/dave/archive/2005/10/30/2550.aspx"&gt;DbProviderFactory&lt;/A&gt; to give you similar database agnostic code ( albeit not as easy to use as the DAAB ) :&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;DbProviderFactory factory &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;DbProviderFactories.GetFactory(providerName);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (DbConnection conn &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; factory.CreateConnection())
{
    conn.ConnectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString;

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; ...&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Fun stuff to play with.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Conclusion&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Hope this helps :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Source:&amp;nbsp;&lt;A href="http://www.davidhayden.com/"&gt;David Hayden&lt;/A&gt; ( &lt;A href="http://www.davidhayden.com/"&gt;Sarasota Web Design&lt;/A&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;ADO.NET 2.0&lt;/A&gt;, &lt;A href="http://davidhayden.com/blog/dave/category/60.aspx?Show=All"&gt;Enterprise Library&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3159.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Using Enterprise Library DAAB and Microsoft Access 2007 via ODBC and OLEDB - Connection Strings and ADO.NET</title><link>http://davidhayden.com/blog/dave/archive/2007/01/28/EnterpriseLibraryDAABMicrosoftAccess2007.aspx</link><pubDate>Sun, 28 Jan 2007 12:16:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2007/01/28/EnterpriseLibraryDAABMicrosoftAccess2007.aspx</guid><description>The Enterprise Library Data Access Application Block can connect to any database that has a .NET Data Provider. One of the common questions is - “Does Enterprise Library support Microsoft Access?“ The answer is yes! You can use OLEDB or ODBC to connect to the Microsoft Access Database using the Data Access Application Block. In this article I show both ways...&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3135.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Caching the Stored Procedure Parameters Discovered Using SqlCommandBuilder.DeriveParameters</title><link>http://davidhayden.com/blog/dave/archive/2006/11/03/CachingStoredProcedureParameters.aspx</link><pubDate>Fri, 03 Nov 2006 15:43:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2006/11/03/CachingStoredProcedureParameters.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;Caching the Stored Procedure Parameters Discovered Using SqlCommandBuilder.DeriveParameters&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida .NET Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Tutorials and Examples&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;A couple days ago I talked about a &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx"&gt;&lt;FONT face=Verdana size=2&gt;DatabaseHelper Library&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; of mine that mimics the functionality in the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;&lt;FONT face=Verdana size=2&gt;Enterprise Library 2.0 Data Access Application Block&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;. To implement the following methods in the DatabaseHelper Library that are in the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;&lt;FONT face=Verdana size=2&gt;DAAB&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ExecuteNonQuery(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues);
IDataReader ExecuteReader(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ExecuteScalar(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues);                
DataSet ExecuteDataSet(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I&amp;nbsp;took advantage of the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx"&gt;&lt;FONT face=Verdana size=2&gt;SqlCommandBuilder.DeriveParameters&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; method that discovers the parameters on stored procedures. You can read the following article for more information: &lt;/FONT&gt;&lt;A id=viewpost.ascx_TitleUrl HREF="/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - ADO.NET Tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Earlier this morning I took a few minutes to add a &lt;STRONG&gt;parameter cache&lt;/STRONG&gt; to help with performance when using the parameter discovery functionality. I didn't want to do it, because it creates additional complexity as well as opens up thread safety issues on a library that wasn't meant for performance critical applications, but I figured what the heck :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;ParameterCache Class&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I outsourced the caching of parameters to a separate caching service - ParameterCache Class. It is nothing but a thread-safe wrapper around a Dictionary Class. Enterprise Library 2.0 DAAB uses a Hashtable, but that was done before generics, etc.&amp;nbsp; I won't bore you with the whole class, but the partial draft cut looks like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ParameterCache : IParameterCache
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Dictionary&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, DbParameter[]&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; dictionary &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Dictionary&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, DbParameter[]&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; syncLock &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ContainsParameters(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString,&lt;BR&gt;                                 &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; dictionary.ContainsKey(&lt;BR&gt;          GetCacheKey(connectionString, storedProcedureName));
    }
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DbParameter[]&lt;BR&gt;        GetParameters(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString,&lt;BR&gt;                                 &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedure)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CopyParameterArray(&lt;BR&gt;           dictionary[GetCacheKey(connectionString,&lt;BR&gt;                                   storedProcedure)]);
    }
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; AddParameters(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString,&lt;BR&gt;                   &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;                   DbParameterCollection parameterCollection)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;ContainsParameters(connectionString,&lt;BR&gt;                                  storedProcedureName))
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;lock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(syncLock)
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;ContainsParameters(connectionString,&lt;BR&gt;                                         storedProcedureName))
                {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; cacheKey &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetCacheKey(connectionString,&lt;BR&gt;                                          storedProcedureName);
                  DbParameter[] parameters &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;GetParameterArray(parameterCollection);
                    
                    dictionary.Add(cacheKey, parameters);
                }
            }
        }
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;All I am doing is delegating most of the work to the Dictionary Class. I added a little &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/06/06/2981.aspx"&gt;&lt;FONT face=Verdana size=2&gt;double-check locking&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; on adding parameters for thread safety, but I have to make sure this is indeed thread safe by doing some testing. Thread safety really becomes an issue when enumerating a Dictionary Class, but we never do that.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Using the Parameter&amp;nbsp;Cache&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;After a bit of refactoring, the code that I mentioned in the previous article has been cut down to this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; IDataReader ExecuteReader(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;                                 &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameters)
{
    SqlCommand command &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;             &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;GetStoredProcCommand(storedProcedureName)&lt;BR&gt;                                             &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlCommand;

    DiscoverParameters(command);

    SetParameterValues(command, parameters);

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ExecuteReader(command);
} &lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I need to add some argument checking, etc., but that is the gist.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The &lt;STRONG&gt;DiscoverParameters Method&lt;/STRONG&gt; now checks the cache to see if the parameters are there before making a roundtrip to the database using &lt;STRONG&gt;SqlCommandBuilder.DeriveParameters&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DiscoverParameters(DbCommand command)
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;FONT color=#ff0000&gt;_cache&lt;/FONT&gt;.ContainsParameters(_connectionString,&lt;BR&gt;                          command.CommandText))
    {
        DbParameter[] parameters &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;FONT color=#ff0000&gt;_cache&lt;/FONT&gt;.GetParameters&lt;BR&gt;                 (_connectionString, command.CommandText);
        command.Parameters.AddRange(parameters);
    }
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (SqlConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;BR&gt;                     &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;CreateConnection() &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlConnection)
        {
            command.Connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection;
            connection.Open();
            SqlCommandBuilder.DeriveParameters(command&lt;BR&gt;                                          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlCommand);
        }

        &lt;FONT color=#ff0000&gt;_cache&lt;/FONT&gt;.AddParameters(_connectionString,&lt;BR&gt;                    command.CommandText, command.Parameters);
    }
}  &lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Conclusion&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Not bad for about an hour this morning. Unit and integration tests are passing, but I need to create ones that assure thread safety :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida .NET Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Tutorials and Examples&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3063.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - ADO.NET Tutorials</title><link>http://davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx</link><pubDate>Wed, 01 Nov 2006 15:36:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - ADO.NET Tutorials&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;ASP.NET C# Sql Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Last night I was updating a DatabaseHelper Library that I use for small .NET consulting projects. It shares the same interface as &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;&lt;FONT face=Verdana size=2&gt;Enterprise Library 2.0 DAAB&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;, but without all the bulk. It is&amp;nbsp;a &amp;#8220;same taste, less filling&amp;#8221; kind of library optimized for Sql Server Database Access that can easily be replaced by the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;&lt;FONT face=Verdana size=2&gt;Data Access Appliction Block&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; with&amp;nbsp;basically no code changes should the need arise.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There are a few methods I hadn't got around to implementing yet since I rarely use them. One is the family of method overloads that take an object array of parameter values as such:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;IDataReader ExecuteReader(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues)&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The idea here is that you want to call a stored procedure that takes some parameters, but you want the convenience of just passing in an object array of parameter values as opposed to creating all the parameters manually. The developer is&amp;nbsp;&amp;#8220;asking&amp;#8221; the library to &amp;#8220;discover&amp;#8220; the proper parameters and assign the values accordingly.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The main reason I don't normally use this overload is because it requires an extra roundtrip to the database by the library to discover the parameters. It is convenient, but not as optimized performance-wise. As an added level of complexity, the &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/08/2686.aspx"&gt;&lt;FONT face=Verdana size=2&gt;DAAB&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; has a parameter cache to cache the parameters discovered on the first call to the stored procedure. This saves you the performance hit on subsequent calls, but just adds complexity to the library as well as cache management.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;SqlCommandBuilder.DeriveParameters&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The magical bit of code that discovers stored procedure parameters in the background is the &lt;STRONG&gt;SqlCommandBuilder.DeriveParameters&lt;/STRONG&gt; method. You call the method passing in an&amp;nbsp;&lt;STRONG&gt;SqlCommand&lt;/STRONG&gt; object as such:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;SqlCommandBuilder.DeriveParameters(command);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;and it will populate the &lt;STRONG&gt;SqlParametersCollection&lt;/STRONG&gt; on the &lt;STRONG&gt;command&lt;/STRONG&gt; for you. Only thing you need to do is populate the input parameters with their appropriate values and execute the query.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;SqlCommandBuilder.DeriveParameters Example&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here is a first cut at what the code might look like to use this functionality:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; IDataReader ExecuteReader(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName,&lt;BR&gt;                       &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;params&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] parameterValues)
{
    SqlConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;try&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    {
        connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CreateConnection();

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Create Command&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        SqlCommand command &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection.CreateCommand();
        command.CommandType &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CommandType.StoredProcedure;
        command.CommandText &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; storedProcedureName;
        
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Open Connection&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        connection.Open();
        
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Discover Parameters for Stored Procedure
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Populate command.Parameters Collection.
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Causes Rountrip to Database.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        SqlCommandBuilder.DeriveParameters(command);

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Initialize Index of parameterValues Array&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; index &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Populate the Input Parameters With Values Provided        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (SqlParameter parameter &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; command.Parameters)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (parameter.Direction &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ParameterDirection.Input &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;||&lt;BR&gt;                 &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;parameter.Direction &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ParameterDirection.&lt;BR&gt;                                             InputOutput)
            {
                parameter.Value &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; parameterValues[index];
                index&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;++&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            }
        }

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; command.ExecuteReader(CommandBehavior.&lt;BR&gt;                                       CloseConnection);
    }
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;amp;&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connection.State&lt;BR&gt;                                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ConnectionState.Open)
            connection.Close();
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You could add some caching here of the parameters so the parameter discovery only happens once.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The client code calling the method may look like:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Call GetBlogsByBlogId Stored Procedure
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; BlogId = 1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (IDataReader dr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ExecuteReader(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;GetBlogByBlogId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;))
{
    Blog blog &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (dr.Read())
    {
        BlogFactory factory &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; BlogFactory();
        blog &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; factory.Construct(dr);
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Conclusion&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Next time you&amp;nbsp;want to&amp;nbsp;find the&amp;nbsp;parameters used&amp;nbsp;by&amp;nbsp;a stored procedure, check out the use of &lt;STRONG&gt;SqlCommandBuilder.DeriveParameters&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Source: &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;ASP.NET C# Sql Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;/FONT&gt;&lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;&lt;FONT face=Verdana size=2&gt;ADO.NET Tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3062.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Get List of Tables in an Access Database - ADO.NET Tutorials</title><link>http://davidhayden.com/blog/dave/archive/2006/10/01/GetListOfTablesInMicrosoftAccessUsingGetSchema.aspx</link><pubDate>Sun, 01 Oct 2006 18:32:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2006/10/01/GetListOfTablesInMicrosoftAccessUsingGetSchema.aspx</guid><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;Get List of Tables in an Access Database - ADO.NET Tutorials&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;ASP.NET C# SQL Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ) Filed: &lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;ADO.NET Tutorials&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;A question came up in the MSDN Forums regarding how to get a list of tables in an Access Database. I have&amp;nbsp;a couple&amp;nbsp;tutorials on how to do this in &lt;A href="http://davidhayden.com/blog/dave/category/14.aspx?Show=All"&gt;SQL Server&lt;/A&gt;, but I never tackled the challenge&amp;nbsp;using Microsoft Access:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/31/2781.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Get List of Tables in a Database - Query INFORMATION_SCHEMA.Tables - ADO.NET&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/03/29/2895.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;GetSchema and DbProviderFactories - List of Tables in a Database&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I thought I wrote an example using &lt;A href="http://davidhayden.com/blog/dave/category/51.aspx"&gt;SQL Server Management Objects ( SMO )&lt;/A&gt;, but I guess not. I will have to add that to the list :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The key is the use of &lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/15/2734.aspx"&gt;GetSchema&lt;/A&gt;, which is new to ADO.NET 2.0. Here is an article I wrote introducing GetSchema:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/15/2734.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;GetSchema - DbConnection.GetSchema in ADO.NET 2.0 - Retrieve Databases Tables Columns Views etc. from Database Connection&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here is the code to get a list of tables in an Access Database, short and sweet:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Microsoft Access provider factory&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;DbProviderFactory factory &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    DbProviderFactories.GetFactory(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;System.Data.OleDb&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);

DataTable userTables &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (DbConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            factory.CreateConnection())
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; c:\test\test.mdb&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    connection.ConnectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;Provider=Microsoft&lt;BR&gt;        .Jet.OLEDB.4.0;Data Source=c:\\test\\test.mdb&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; We only want user tables, not system tables&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] restrictions &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;4&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;];
    restrictions[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;3&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;] &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;Table&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
    
    connection.Open();
    
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Get list of user tables&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    userTables &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        connection.GetSchema(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;Tables&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, restrictions);
}

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Add list of table names to listBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;for&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; i&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;; i &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; userTables.Rows.Count; i&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;++&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
    listBox1.Items.Add(userTables.Rows[i][&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;2&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ToString());&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The userTables DataTable looks like this using the DataSet Visualizer:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=center&gt;&lt;FONT face=Verdana size=2&gt;&lt;IMG alt="get list of tables in access database" src="http://www.davidhayden.com/photos/getschemaaccess.jpg"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Pretty simple once you get to appreciate &lt;A href="http://davidhayden.com/blog/dave/archive/2006/01/15/2734.aspx"&gt;GetSchema&lt;/A&gt;. Hope this helps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Written By: &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; ( &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;ASP.NET C# SQL Server Developer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Filed: &lt;A href="http://davidhayden.com/blog/dave/category/26.aspx?Show=All"&gt;ADO.NET Tutorials&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3056.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Dave Hayden</dc:creator><title>Enterprise Library 2.0 DAAB - Retrieving PK and Timestamp When Inserting New Record</title><link>http://davidhayden.com/blog/dave/archive/2006/07/26/EnterpriseLibraryPKAndTimestamp.aspx</link><pubDate>Wed, 26 Jul 2006 13:53:00 GMT</pubDate><guid>http://davidhayden.com/blog/dave/archive/2006/07/26/EnterpriseLibraryPKAndTimestamp.aspx</guid><description>I was answering a number of questions on the Enterprise Library 2.0 DAAB Message Board today, and this one was worth a blog post since the question comes up a lot in various forums. Although I am showing this using Enterprise Library 2.0 DAAB, the answer applies to SqlClient as well. Let's say you're inserting a new customer row in the Customers Table and you want to retrieve the PK and Timestap ( Rowversion ) of the row..
&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3013.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>