How to detect Connection Type name from Connection string in .net

Is there new or existing method parse a connection string’s keys to determine the connection type (OleDbConnection, OdbcConnection, SqlConnection, MySqlConnection, DB2Connetrion, etc) ?

The result doesn’t meet to be the actual DbConnection, but either a string of the name or an enum of connection types parsed names.

For example if:

  • contains key “provider” it is OleDbConnection.
  • contains key “driver” it is OdbcConnection.

1 answer

  1. la forma de conectarte con odbc mediante . net es mediante la clase System.Data.Odbc de esta heredan varios name space losc uales son using System.Data.Common using System.Data.ProviderBase, de aqui es necesario realizar el llamado a las propiedades command As Odbc.OdbcCommand y Public Shared Cnn As Odbc.OdbcConnection que la utlima ejecuta la apertura para la cadena de coenxion si la coenxion la desea realizar a una bvase de dato como dbsiam que la uncia forma de poder conectar es mediante driver DBISAM 4 ODBC Driver es necesario apsar un string con el nombre d ela ubciacion de la carpeta data y luego hacer le llamado al odbcConnection
    Ejemplo forma de conexion en Visual basic

     Const UBICAICON= "NOMBRE-UBICACION DE LA CARPETA"
     Const stConectionConst = "DRIVER={DBISAM 4 ODBC Driver};UID=;PrivateDirectory=c:\a2Temp\;MRUPrivateDirectory1=c:\a2Temp\;StrictChangeDetection=True;ForceBufferFlush=false;LockWaitTime=1000;LockRetryCount=15;ReadOnly=False;CatalogName=@DIRECTORIO;MRUDatabase2=@DIRECTORIO;MRUDatabase1=Memory;RemoteReadAhead=50;RemoteEncryptionPassword=elevatesoft;RemoteEncryption=False;RemotePingInterval=60;RemotePing=False;RemoteCompression=0;RemoteService=;RemotePort=12005;RemoteIPAddress=127.0.0.1;RemoteHostName=;ConnectionType=Local"
    
     Dim stConection = Replace(stConectionConst, "@DIRECTORIO", UBICAICON)
    
     Cnn = New OdbcConnection(stConection)
     ''Cnn = New OdbcConnection("DRIVER={DBISAM 4 ODBC Driver};UID=;PrivateDirectory=c:\a2Temp\;MRUPrivateDirectory1=c:\a2Temp\;StrictChangeDetection=True;ForceBufferFlush=false;LockWaitTime=200;LockRetryCount=15;ReadOnly=False;CatalogName=@DIRECTORIO;MRUDatabase2=@DIRECTORIO;MRUDatabase1=Memory;RemoteReadAhead=50;RemoteEncryptionPassword=elevatesoft;RemoteEncryption=False;RemotePingInterval=60;RemotePing=False;RemoteCompression=0;RemoteService=;RemotePort=12005;RemoteIPAddress=127.0.0.1;RemoteHostName=;ConnectionType=Local")