FdoToolbox.Tasks.Services.TaskLoader.CreateConnection C# (CSharp) Method

CreateConnection() protected method

Creates the connection.
protected CreateConnection ( string provider, string connStr, string configPath, string &name ) : FdoConnection
provider string The provider.
connStr string The connection string.
configPath string The configuration path
name string The name that will be assigned to the connection.
return FdoToolbox.Core.Feature.FdoConnection
        protected override FdoConnection CreateConnection(string provider, string connStr, string configPath, ref string name)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
            //Try to find by name first
            FdoConnection conn = null;
            conn = connMgr.GetConnection(name);
            //Named connection matches all the details
            if (conn != null)
            {
                if (conn.Provider == provider && conn.ConnectionString == connStr)
                    return conn;
            }

            //Then to find matching open connection
            foreach (string connName in connMgr.GetConnectionNames())
            {
                FdoConnection c = connMgr.GetConnection(connName);
                if (c.Provider == provider && c.ConnectionString == connStr)
                {
                    name = connName;
                    return c;
                }
            }

            //Make a new connection
            LoggingService.Info(ResourceService.GetString("INFO_REFERENCED_CONNECTION_NOT_FOUND"));
            conn = new FdoConnection(provider, connStr);
            if (!string.IsNullOrEmpty(configPath) && System.IO.File.Exists(configPath))
                conn.SetConfiguration(configPath);
            connMgr.AddConnection(name, conn);
            return conn;
        }