The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by glsac]

Well...I bought this book a while back, and although I ahve been coding .NET
for close to 2 years, this book has shown me a few new things...and the idea
of coding generic code for connections IMO was ever so helpful...I would liek
to share with you, and with anyone else interested in what I did for generic
connections:

First off in the web.config file...or if you create a GUI in an app.config
file add the following keys:

<!-- Provider to use, values SqlClient, OleDb, Odbc, Oracle -->
<add key="ProviderType" value="SqlClient" />
<!-- Conn String -->
<add key="MyConnectionString" value="Initial Catalog=MyDB;Data<br /> Source=localhost;user id=;password=" />


My db.cs file then calls this...I can't post the whole class (it's huge) but
here are the important parts:

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Xml;

using System.Data.Odbc;
using System.Data.OracleClient;

public class DataAccess :IDisposable
{
IDbConnection _connection;
IDbDataAdapter _DataAdapter;
string Provider = null;

public DataAccess()
{
// getting connection string first
string CS =
System.Configuration.ConfigurationSettings.AppSettings["MyConnectionString"];
// using common interfaces for .net data providers
Provider =
System.Configuration.ConfigurationSettings.AppSettings["ProviderType"];
switch (Provider)
{
case "SqlClient" : _connection = new SqlConnection(CS);_DataAdapter = new
SqlDataAdapter();break;
case "OleDb": _connection = new OleDbConnection(CS);_DataAdapter = new
OleDbDataAdapter();break;
case "Odbc": _connection = new OdbcConnection(CS);_DataAdapter = new
OdbcDataAdapter();break;
case "Oracle": _connection = new OracleConnection(CS);_DataAdapter =
new OracleDataAdapter();break;
default : break;//Response.Write("<STRONG>Error in parameter :
ProviderType</STRONG>");Response.End();break;
}
_connection.Open();
}

Now for the parameters I use this:

// returns parameter name
private string pn(string name)
{
switch (Provider)
{
case "SqlClient" :
return "@" + name;
case "OleDb" : case "Odbc":
return "?";
case "Oracle":
return ":" + name;
default: return "@" + name;
}

Then I also use for command object the IDbCommand Interface. Granted I am only
connecting to SQL Server in my scenario, but I may be moving to Oracle. Now
alos ading MySQL or something like that is easy to do. No need to recompile
project this way, just simply change it in the web or app.config which as we
all know is XML style, and can change things on the fly.

Yes, there are 2 "draw backs":

1. This took a while longer to code out, and my database class is well closing
in on >7 thousand lines...for a db class I did not think it would ever be that
long...

2. I did not use sprocs...I coded all ANSI sql directly in the code, but using
sprocs again would have been easy, I can then just call the sprocs if the
ProviderType is for SQL Server.

Well in any event a great book..I enjoyed it a lot...and when do you think you
willc oem out with another one? smilie

-Joe
import-bot (20211) [Avatar] Offline
#2
Re: Wonderful Book
[Originally posted by arlen]

Many thanks for the comments and for the suggestions.

I am working on another book right now, but it is more for managers. I am not
sure what topic to tackle next for a technical book.

Arlen
import-bot (20211) [Avatar] Offline
#3
Re: Wonderful Book
[Originally posted by glsac]

I would be interested in hearing more on that book...as a hands-on manager
myself, I am curious as to what you have smilie Would also love to read any early
versions...would be my pleasure!

On a side note, I have a few suggestions for technical book(s):

1. Crystal reports and the .NET platform...ok more crystal book than anything,
but as Crystal is used often, and yet no realy good books on it.

2. Advanced ADO.NET Case Studies...reading in your book, you stated that you
did not have much time to put any case studies in...I think a book with real
case studies would be so helpful. Any case studies, asp.net or winforms with
connections to SQL Server, Oracle, or as I have done XML with backend back to
any one of the above smilie

3. This may be in your managers book (which would be great btw if it
is)..basically Project Management, and gathering of data and details etc.

Hehe...maybe one day I'll write one smilie

Thanks!
-Joe