Exemplo n.º 1
0
        public override ConnectionManager AddConnectionManager(Package package)
        {
            ConnectionManager connMgr = package.Connections.Add("Excel") as ConnectionManager;

            connMgr.Name             = ConnectionMgrName;
            connMgr.ConnectionString = ConnectionString;
            wrapper.IDTSConnectionManagerExcel100 excelConMgr = connMgr.InnerObject as wrapper.IDTSConnectionManagerExcel100;
            excelConMgr.ExcelFilePath         = filePath;
            excelConMgr.FirstRowHasColumnName = firstRowHasColName;
            return(connMgr);
        }
Exemplo n.º 2
0
        public void AddConnection(Connection connection)
        {
            ConnectionManager SSISConnection;

            if (connection.ConnectionType == ConnectionTypes.OleDBConnection)
            {
                // Add the OLEDB connection manager.
                ConnectionManager oleDB = _Package.Connections.Add("OLEDB");

                // Set stock properties.
                oleDB.Name             = connection.Key;
                oleDB.ConnectionString = connection.ConnectionString;
                SSISConnection         = oleDB;
            }
            else if (connection.ConnectionType == ConnectionTypes.FileConnection)
            {
                ConnectionManager File = _Package.Connections.Add("FILE");
                File.ConnectionString = connection.ConnectionString;
                File.Name             = connection.Key;

                SSISConnection = File;
            }
            else if (connection.ConnectionType == ConnectionTypes.FlatFileConnection)
            {
                // Add the Destination connection manager.
                ConnectionManager csvFile = _Package.Connections.Add("FLATFILE");

                // Set the stock properties.
                csvFile.ConnectionString = connection.ConnectionString;
                csvFile.Name             = connection.Key;

                csvFile.Properties["Format"].SetValue(csvFile, "Delimited");
                csvFile.Properties["DataRowsToSkip"].SetValue(csvFile, 0);
                csvFile.Properties["ColumnNamesInFirstDataRow"].SetValue(csvFile, true);
                csvFile.Properties["RowDelimiter"].SetValue(csvFile, "\r\n");
                csvFile.Properties["TextQualifier"].SetValue(csvFile, "\"");

                SSISConnection = csvFile;
            }
            else if (connection.ConnectionType == ConnectionTypes.ExcelConnection)
            {
                ConnectionManager connMgr = _Package.Connections.Add("Excel");
                connMgr.Name = connection.Key;

                string XlConnectionString = String.Format(CultureInfo.InvariantCulture, "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=YES\";", connection.ConnectionString);
                connMgr.ConnectionString = XlConnectionString;

                wrap.IDTSConnectionManagerExcel100 excelConMgr = connMgr.InnerObject as wrap.IDTSConnectionManagerExcel100;
                excelConMgr.ExcelFilePath = connection.ConnectionString;
                //TODO: Can be exposed to config
                excelConMgr.FirstRowHasColumnName = true;

                SSISConnection = connMgr;
            }
            else if (connection.ConnectionType == ConnectionTypes.SMTPConnection)
            {
                ConnectionManager smtp = _Package.Connections.Add("SMTP");
                smtp.ConnectionString = connection.ConnectionString;
                smtp.Name             = connection.Key;
                SSISConnection        = smtp;
            }
            else if (connection.ConnectionType == ConnectionTypes.SharePointListConnection)
            {
                //ConnectionManager sharePointList = _Package.Connections.Add("SPCRED");
                //sharePointList.ConnectionString = connection.ConnectionString;
                //sharePointList.Name = connection.Key;
                //SSISConnection = sharePointList;
                SSISConnection = null;
            }
            else if (connection.ConnectionType == ConnectionTypes.TableStorageConnection)
            {
                //to do
                SSISConnection = null;
            }
            else
            {
                throw new Exception("Invalid Connection Type");
            }
            _ConnectionDic.Add(connection.Key, SSISConnection);
            _ConnectionStr.Add(connection.Key, connection.ConnectionString);
        }