Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Connect to the database with more than one single layer.

Connect to the database with more than one single layer.

Scheduled Pinned Locked Moved Database
databasemysqlsql-serveroraclecom
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    baymyo
    wrote on last edited by
    #1

    Description Image http://baymyo.com/gallery/pimage/multi_sql_code_generate_gif-50cf8.gif[^] Open Source Code, Downlaod Click Here! MSSQL, ORACLE, MySQL, and OleDb to establish connections to servers via a single layer. The following block of code to show the connection layer.

    public class MConnection : IDisposable
    {
    #region IDisposable Members
    public void Dispose()
    {
    this.Close();
    if (this.m_ClientConnection != null)
    this.m_ClientConnection.Dispose();
    GC.SuppressFinalize(this);
    }
    #endregion

        #region --- Member ---
        IMConnection m\_ClientConnection;
        internal IMConnection ClientConnection
        {
            get { return m\_ClientConnection; }
        }
    
        private MClientProvider m\_ClientProvider;
        public MClientProvider ClientProvider
        {
            get { return m\_ClientProvider; }
        }
    
        private string m\_ConnectionString;
        public string ConnectionString
        {
            get { return m\_ConnectionString; }
        }
    
        private System.Data.ConnectionState m\_State;
        public System.Data.ConnectionState State
        {
            get { return m\_State; }
        }
    
        public System.ComponentModel.ISite Site
        {
            get
            {
                return m\_ClientConnection.Site;
            }
            set
            {
                m\_ClientConnection.Site = value;
            }
        }
    
        public string ServerVersion
        {
            get
            {
                return m\_ClientConnection.ServerVersion;
            }
        }
    
        public string Database
        {
            get
            {
                return m\_ClientConnection.Database;
            }
        }
    
        public string DataSource
        {
            get
            {
                return m\_ClientConnection.DataSource;
            }
        }
        #endregion
    
        #region --- Constructor ---
        public MConnection(MClientProvider clientProvider)
        {
            this.m\_ClientProvider = clientProvider;
            switch (this.m\_Cli
    
    L L J 3 Replies Last reply
    0
    • B baymyo

      Description Image http://baymyo.com/gallery/pimage/multi_sql_code_generate_gif-50cf8.gif[^] Open Source Code, Downlaod Click Here! MSSQL, ORACLE, MySQL, and OleDb to establish connections to servers via a single layer. The following block of code to show the connection layer.

      public class MConnection : IDisposable
      {
      #region IDisposable Members
      public void Dispose()
      {
      this.Close();
      if (this.m_ClientConnection != null)
      this.m_ClientConnection.Dispose();
      GC.SuppressFinalize(this);
      }
      #endregion

          #region --- Member ---
          IMConnection m\_ClientConnection;
          internal IMConnection ClientConnection
          {
              get { return m\_ClientConnection; }
          }
      
          private MClientProvider m\_ClientProvider;
          public MClientProvider ClientProvider
          {
              get { return m\_ClientProvider; }
          }
      
          private string m\_ConnectionString;
          public string ConnectionString
          {
              get { return m\_ConnectionString; }
          }
      
          private System.Data.ConnectionState m\_State;
          public System.Data.ConnectionState State
          {
              get { return m\_State; }
          }
      
          public System.ComponentModel.ISite Site
          {
              get
              {
                  return m\_ClientConnection.Site;
              }
              set
              {
                  m\_ClientConnection.Site = value;
              }
          }
      
          public string ServerVersion
          {
              get
              {
                  return m\_ClientConnection.ServerVersion;
              }
          }
      
          public string Database
          {
              get
              {
                  return m\_ClientConnection.Database;
              }
          }
      
          public string DataSource
          {
              get
              {
                  return m\_ClientConnection.DataSource;
              }
          }
          #endregion
      
          #region --- Constructor ---
          public MConnection(MClientProvider clientProvider)
          {
              this.m\_ClientProvider = clientProvider;
              switch (this.m\_Cli
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      What is this? is there a question hidden somewhere? this is a discussion forum. If you want to share something, write an article, don't just dump a bunch of undocumented code. :doh:

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      L 1 Reply Last reply
      0
      • L Luc Pattyn

        What is this? is there a question hidden somewhere? this is a discussion forum. If you want to share something, write an article, don't just dump a bunch of undocumented code. :doh:

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I think he/she is developing a taste for Spam.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        L 1 Reply Last reply
        0
        • L Lost User

          I think he/she is developing a taste for Spam.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I realize we can't get Bacon all the time. :-D

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          1 Reply Last reply
          0
          • B baymyo

            Description Image http://baymyo.com/gallery/pimage/multi_sql_code_generate_gif-50cf8.gif[^] Open Source Code, Downlaod Click Here! MSSQL, ORACLE, MySQL, and OleDb to establish connections to servers via a single layer. The following block of code to show the connection layer.

            public class MConnection : IDisposable
            {
            #region IDisposable Members
            public void Dispose()
            {
            this.Close();
            if (this.m_ClientConnection != null)
            this.m_ClientConnection.Dispose();
            GC.SuppressFinalize(this);
            }
            #endregion

                #region --- Member ---
                IMConnection m\_ClientConnection;
                internal IMConnection ClientConnection
                {
                    get { return m\_ClientConnection; }
                }
            
                private MClientProvider m\_ClientProvider;
                public MClientProvider ClientProvider
                {
                    get { return m\_ClientProvider; }
                }
            
                private string m\_ConnectionString;
                public string ConnectionString
                {
                    get { return m\_ConnectionString; }
                }
            
                private System.Data.ConnectionState m\_State;
                public System.Data.ConnectionState State
                {
                    get { return m\_State; }
                }
            
                public System.ComponentModel.ISite Site
                {
                    get
                    {
                        return m\_ClientConnection.Site;
                    }
                    set
                    {
                        m\_ClientConnection.Site = value;
                    }
                }
            
                public string ServerVersion
                {
                    get
                    {
                        return m\_ClientConnection.ServerVersion;
                    }
                }
            
                public string Database
                {
                    get
                    {
                        return m\_ClientConnection.Database;
                    }
                }
            
                public string DataSource
                {
                    get
                    {
                        return m\_ClientConnection.DataSource;
                    }
                }
                #endregion
            
                #region --- Constructor ---
                public MConnection(MClientProvider clientProvider)
                {
                    this.m\_ClientProvider = clientProvider;
                    switch (this.m\_Cli
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            internal MCommand(object command, MConnection connection)
            {
            try
            {
            this.m_Connection = connection;
            switch (connection.ClientProvider)
            {
            case MClientProvider.MSSQL:
            this.m_ClientCommand = new MSSQLCommand(command as System.Data.SqlClient.SqlCommand);
            break;
            case MClientProvider.ORACLE:
            this.m_ClientCommand = new ORACLECommand(command as System.Data.OracleClient.OracleCommand);
            break;
            case MClientProvider.MySQL:
            break;
            case MClientProvider.OleDb:
            this.m_ClientCommand = new OLEDBCommand(command as System.Data.OleDb.OleDbCommand);
            break;
            }
            this.m_ClientCommand.Connection = connection;
            this.m_CommandText = this.m_ClientCommand.CommandText;
            this.m_CommandType = this.m_ClientCommand.CommandType;
            this.m_CommandTimeout = this.m_ClientCommand.CommandTimeout;
            }
            catch (Exception ex)
            {
            throw ex;
            }

            Loose the switch, and have the connection create[^] a command;

            command = connection.CreateCommand();

            It'd also be wise to remove the redunant error-handler. Catching an exception merely to rethrow it doesn't make much sense. If you really feel like it, then make it

            catch (Exception ex)
            {
            throw;
            }

            Bastard Programmer from Hell :suss:

            1 Reply Last reply
            0
            • B baymyo

              Description Image http://baymyo.com/gallery/pimage/multi_sql_code_generate_gif-50cf8.gif[^] Open Source Code, Downlaod Click Here! MSSQL, ORACLE, MySQL, and OleDb to establish connections to servers via a single layer. The following block of code to show the connection layer.

              public class MConnection : IDisposable
              {
              #region IDisposable Members
              public void Dispose()
              {
              this.Close();
              if (this.m_ClientConnection != null)
              this.m_ClientConnection.Dispose();
              GC.SuppressFinalize(this);
              }
              #endregion

                  #region --- Member ---
                  IMConnection m\_ClientConnection;
                  internal IMConnection ClientConnection
                  {
                      get { return m\_ClientConnection; }
                  }
              
                  private MClientProvider m\_ClientProvider;
                  public MClientProvider ClientProvider
                  {
                      get { return m\_ClientProvider; }
                  }
              
                  private string m\_ConnectionString;
                  public string ConnectionString
                  {
                      get { return m\_ConnectionString; }
                  }
              
                  private System.Data.ConnectionState m\_State;
                  public System.Data.ConnectionState State
                  {
                      get { return m\_State; }
                  }
              
                  public System.ComponentModel.ISite Site
                  {
                      get
                      {
                          return m\_ClientConnection.Site;
                      }
                      set
                      {
                          m\_ClientConnection.Site = value;
                      }
                  }
              
                  public string ServerVersion
                  {
                      get
                      {
                          return m\_ClientConnection.ServerVersion;
                      }
                  }
              
                  public string Database
                  {
                      get
                      {
                          return m\_ClientConnection.Database;
                      }
                  }
              
                  public string DataSource
                  {
                      get
                      {
                          return m\_ClientConnection.DataSource;
                      }
                  }
                  #endregion
              
                  #region --- Constructor ---
                  public MConnection(MClientProvider clientProvider)
                  {
                      this.m\_ClientProvider = clientProvider;
                      switch (this.m\_Cli
              
              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #6

              Seriously, why do you reinvent the wheel, badly. It's already been done, by Microsoft. So read up on DBProviderFactories[^] instead. A little on how to use them here[^].

              Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups