diff options
author | Daniel Morgan <monodanmorg@yahoo.com> | 2003-02-17 18:03:43 +0300 |
---|---|---|
committer | Daniel Morgan <monodanmorg@yahoo.com> | 2003-02-17 18:03:43 +0300 |
commit | 192ac46f0a95908428901bf0bc9d66e47c72a1df (patch) | |
tree | a4d32171d67ea7de6eeb56c420131f2337e651e3 /web/provider-factory | |
parent | f369737334b5d047ca5702e819b56b6b18c689c3 (diff) |
2003-02-17 Daniel Morgan <danmorg@sc.rr.com>
* doc/provider-factory: add new web page
about Mono.Data's ProviderFactory
* doc/web/commands
* doc/web/makefile: add provider-factory web page to build
* doc/ado-net
* doc/ibmdb2
* doc/postgresql
* doc/sqlclient
* doc/tdsclient
* doc/sybase
* doc/mysql
* doc/firebird
* doc/oracle
* doc/oledb
* doc/odbc
* doc/sqlite: updated web pages
svn path=/trunk/mono/; revision=11639
Diffstat (limited to 'web/provider-factory')
-rwxr-xr-x | web/provider-factory | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/web/provider-factory b/web/provider-factory new file mode 100755 index 00000000000..37309ec4324 --- /dev/null +++ b/web/provider-factory @@ -0,0 +1,156 @@ +* Provider Factory + +<p>Brian Ritchie contributed a Provider Factory and Data Tools for Mono ADO.NET<br> +which gives us a foundation for abstract data provider access within Mono + +** Here are the deails: + +<ul> + <li>The Provider information is seperate from the connection string information.<br> + This allows the list of providers to be stored in the machine.config file.</li> + <li>Provider and ProviderCollection objects are available to access <br> + the list of providers and modify them at runtime.</li> + <li>The ProviderFactory object is used to create new connections, commands,<br> + dataadapters, parameters, etc.</li> +</ul> + +** Overview of the ProviderFactory object model: + +<ul> + <li><b>ProviderFactory</b>: used to create new Connections, Commands,<br> + DataAdapters, or Commands. All objects are returned using <br> + the provider interfaces such as IDbConnection, IDbCommand,<br> + IDbDataAdapter, or IDataParamter</li> + + <li><b>DataTools</b>: static methods for doing <br> + common tasks like filling a DataSet <br> + with the contents of a select statement.</li> + + <li><b>ProviderCollection</b>: list of providers configured <br> + in the system. Initially loaded from app.config, but can <br> + be modified at run-time.</li> + + <li><b>Provider</b>: represents a given provider (factory) <br> + and holds information needed to <br> + create the types.</li> + + <li><b>ProviderSectionHandler</b>: works behind the <br> + scenes to load the list of <br> + providers from the app.config into a ProviderCollection.</li> +</ul> + +** C# source code samples for creating a connection: + +<pre> + // Create connection using enhanced connection string + // The factory attribute specifies which provider + // to use. The factory attribute is parsed out, the + // object is created, and then the rest of the + // connection string is passed into the provider. The + // providers are defined in + // the app.config (or machine.config). + IDbConnection conn; + string connectionString = + "factory=System.Data.SqlClient;" + + "server=speedy;database=pubs;uid=sa"; + conn = ProviderFactory.CreateConnection(connectionString); + + // Create connection specifying provider + // and standard connection string + IDbConnection conn; + string provider = "System.Data.SqlClient"; + string connectionString = "server=speedy;database=pubs;uid=sa"; + conn = ProviderFactory.CreateConnection(provider,connectionString); + + // Create connection using connection string stored + // in app.config under <appSettings> + IDbConnection conn; + string appSetting = "PubsConnStr"; + conn = ProviderFactory.CreateConnectionFromConfig(appSetting); +</pre> + + +<p>C# Sample for Creating a DataAdapter and filling a DataSet. + +<pre> +// Create Connection +IDbConnection conn = +ProviderFactory.CreateConnectionFromConfig("PubsConnStr"); + +// Select command +IDbCommand cmd=conn.CreateCommand(); +cmd.Text="select * from author"; + +// Data Adapter +DataSet ds=new DataSet(); +IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(cmd); +adapter.Fill(ds, "Table1"); +</pre> + +<p>Creating a DataAdapter and filling a DataSet. <br> +The super lazy method for people like me. +<pre> +// Create Connection +IDbConnection conn = +ProviderFactory.CreateConnectionFromConfig("TdsPubsConnStr"); + +// Data Adapter +DataSet ds=DataTools.FillDataSet(conn, "select * from author"); +</pre> + + +<p>Here's some sample code on displaying a list <br> + of configured ADO.NET providers: +<pre> +Console.WriteLine("Configured Providers:"); +foreach (Provider p in ProviderFactory.Providers) + Console.WriteLine(p.Description); +</pre> + +<p>A Super lazy overload to the FillDataSet method (in <br> +DataTools.cs) that will fill a dataset in one line of code. + +<pre> +DataSet ds=DataTools.FillDataSet("PubsConnStr", "select * from authors"); +</pre> + +** About Configuration Files + +<p>Information about <a href="http://msdn.microsoft.com/library/en-us/vbcon/html/vboriintroductiontoapplicationsettingstorage.asp?frame=true">app.config</a> files +can be found at <a href="http://msdn.microsoft.com/">MSDN</a>. + +<p>See the mcs/class/Mono.Data/app.config for sample configuration file in<br> +mcs source. Basically, if your application is named blah.exe, <br> +you would create an app.config file named blah.exe.config + +<p>Here's a sample app.config file showing the provider <br> +declarations along with sample connection strings: + +<pre> + +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <configSections> + <sectionGroup name="mono.data"> + <section name="providers" type="Mono.Data.ProviderSectionHandler,Mono.Data" /> + </sectionGroup> + </configSections> + <appSettings> + <add key="PubsConnStr" value="factory=System.Data.SqlClient;server=speedy;database=pubs;uid=sa;pwd=" /> + </appSettings> + <mono.data> + <providers> + <provider name="System.Data.SqlClient" connection="System.Data.SqlClient.SqlConnection" adapter="System.Data.SqlClient.SqlDataAdapter" assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.OleDb" connection="System.Data.OleDb.OleDbConnection" adapter="System.Data.OleDb.OleDbDataAdapter" assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.Odbc" connection="System.Data.Odbc.OdbcConnection" adapter="System.Data.OleDb.OdbcDataAdapter" assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> + <provider name="Mono.Data.TdsClient" connection="Mono.Data.TdsClient.TdsConnection" adapter="Mono.Data.TdsClient.TdsDataAdapter" assembly="Mono.Data.TdsClient" /> + <provider name="Mono.Data.MySql" connection="Mono.Data.MySql.MySqlConnection" adapter="Mono.Data.MySql.MySqlDataAdapter" assembly="Mono.Data.MySql" /> + <provider name="Mono.Data.PostgreSqlClient" connection="Mono.Data.PostgreSqlClient.PgSqlConnection" adapter="Mono.Data.PostgreSqlClient.PgSqlDataAdapter" assembly="Mono.Data.PostgreSqlClient" /> + <provider name="Mono.Data.SqliteClient" connection="Mono.Data.SqliteClient.SqliteConnection" adapter="Mono.Data.SqliteClient.SqliteDataAdapter" assembly="Mono.Data.SqliteClient" /> + <provider name="Mono.Data.SybaseClient" connection="Mono.Data.SybaseClient.SybaseConnection" adapter="Mono.Data.SybaseClient.SybaseDataAdapter" assembly="Mono.Data.SybaseClient" /> + </providers> + </mono.data> +</configuration> + +</pre> + |