Advertisement

04.16.2008 at 06:13AM PDT, ID: 23326929
[x]
Attachment Details

Using IDbConnection - ADO.NET

Asked by singhch in Microsoft Visual C#.Net, ADO.Net Class Library

Hi there,

I am creating a method where I can pass a connection string and depending on which provider i have chosen, this method will create a connection from the appropriate provider.  below is a sample of my code.

       public IDbConnection CreateConnection(string connectionString)
        {
            IDbConnection conn = null;
            object[] args = { connectionString };

            try
            {
                switch (_provider)
                {
                    case ProviderType.OleDb:
                        conn = new OleDbConnection(connectionString);
                        var myconn = new OleDbConnection(connectionString);
                        break;
                    case ProviderType.SqlClient:
                        conn = new SqlConnection(connectionString);
                        break;
                    case ProviderType.SybaseClient:
                        conn = new AseConnection(connectionString);
                        break;
                    case ProviderType.DDTekSybaseClient:
                        conn = new SybaseConnection(connectionString);
                        break;
                }
            }
            catch (TargetInvocationException e)
            {
                throw new SystemException(e.InnerException.Message, e.InnerException);
            }

            return conn;
        }

however my attemp to connect to the database, stating that it cannot initialize the connection. so after investigating, i realised that the "conn" variable which is IDbConnection doesnt hold all the parameters required as compared to a OleDbConnection type.  

But I thought that OleDbConnection inherits from IDbConnection. So what can I do to achieve my goal?  thanksStart Free Trial
[+][-]04.16.2008 at 06:36AM PDT, ID: 21367583

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 02:17PM PDT, ID: 21372047

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 03:26PM PDT, ID: 21372591

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 03:32PM PDT, ID: 21372615

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, ADO.Net Class Library
Sign Up Now!
Solution Provided By: graye
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628