replicating a IDBCommand conection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • george1106
    New Member
    • Oct 2006
    • 14

    replicating a IDBCommand conection

    Hi everyone...

    I just was wondoring if there's a way to replicate or Clone a IDBConnection in an application.. look I'm working in a team that is developing app clientes to a kind of DB, that provide us with connections and all functionality necesary, we send instrucctions to this object and it make them happen (because it should be able to work in diferentes DB engines and it should be transparent for the clients we make)... well, the proplem is: we only have 1 IDBConnection shared into 4 clients (Historic register, reports, tendencies, and I can't remeber the other) and when ther try to work together ther interrupt each other... because the connection is occuped.

    as I say before, i want to derivate or clone a Connection from this original IDBConnection provided from the central App.

    If anyone knows at least a direction, it will be to appreciate.
    thanks in advance :D
  • george1106
    New Member
    • Oct 2006
    • 14

    #2
    Hi there!

    I found the solution.. I just needed to create a new object with an IDBCommand wich I make an instance with the kind of the original connection (I used a switch)

    IDBConnection conexion;
    switch(original Connection.GetT ype().ToString( ))
    {
    case "System.Data.Sq lConnection":
    conexion = new SqlConnection() ;
    break;
    case "NpgsqlConnecti on":
    conexion = new NpgsqlConnectio n();
    break;
    }
    conexion.Connec tionString = originalConnect ion.ConnectionS tring;
    conexion.Open() ;

    so that's all. I hope this help someone.

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Well done :) - thanks for sharing the solution.

      Comment

      • sanketshete3
        New Member
        • Sep 2021
        • 1

        #4
        You should not rely on copying connection string directly from connection object,
        When Persist Security Info = False, is set in the connection string, In that case, Password
        will not be set to the connection string, so you might face a login failed error.

        Comment

        Working...