在运行时

时间:2017-10-20 15:53:34

标签: c# sql ssis

    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.OleDb; 

     public void Main()
            {
                OleDbConnection objConnection = null;
                string strConnection= string.Empty; 
                try
                {
                    string[] sourcefiles = Directory.GetFiles(Dts.Variables["User::FilePath"].Value.ToString());
                    string strFileQualifiedName = Convert.ToString(Dts.Variables["User::FilePath"].Value)
                                         + "\\" + Convert.ToString(Dts.Variables["User::FileName"].Value);

                    //Provider for excel 2007
                     strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strFileQualifiedName + ";Extended Properties=\"Excel 12.0 XML;HDR=NO\"";              

                    if (Directory.Exists(Convert.ToString(Dts.Variables["User::FilePath"].Value)))
                    {
                        FileInfo fileInfo = new FileInfo(strFileQualifiedName);
                        if (fileInfo.Exists)
                        { 
                 // I think it fails in the next line
                            objConnection = new OleDbConnection(strConnection); 
                            objConnection.Open();
                            DataRow[] drWorkSheets = objConnection.GetSchema("Tables").Select("TABLE_NAME = '" + Convert.ToString(Dts.Variables["User::WorkSheetName"].Value).Trim() + "$'");
                            if (drWorkSheets.Length == 1)
                            {
                                Dts.Variables["User::IsWorkSheetFound"].Value = true;
                            }
                            else
                            {
                                Dts.Variables["User::IsWorkSheetFound"].Value = false;
                            }
                            objConnection.Close();
                        }
                        else
                        {
                            Dts.Variables["User::IsWorkSheetFound"].Value = false;
                        }
                    }
                    else
                    {
                        Dts.Variables["User::IsWorkSheetFound"].Value = false;
                    }

                    Dts.TaskResult = (int)ScriptResults.Success;
                }
                catch (Exception ex)
                {
                    Dts.TaskResult = (int)ScriptResults.Failure;
                    Dts.Variables["User::StatusDescription"].Value = "Check Work Sheet Error: " + ex.Message + "Stack Trace: " + ex.StackTrace + "Connection string: " + strConnection;
                }
                finally
                {
                    if (objConnection != null)
                    {
                        if (objConnection.State == ConnectionState.Open)
                        {
                            objConnection.Close();
                        }
                        objConnection.Dispose();
                        objConnection = null;
                    }
                }
            }
        }
    }

Stake Trace: 堆栈跟踪:在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接)    在System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningObject)    在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionOptions userOptions)    在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions userOptions)    在System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)    在System.Data.OleDb.OleDbConnection.Open()    at ST_a451219206e54e21b4be51b95b706a1b.csproj.ScriptMain.Main()连接字符串:Provider = Microsoft.ACE.OLEDB.12.0;数据源= \ RRWIN-FSSSISE01 \ File \ SSISData \ LoadFiles \ Import \ TrialBalanceDef_08afd8dc-38b7-4ea5-80c3-8b7e7ce383b5 \ 0552d0b9 -8abe-4b3f-9b7b-43e47c1d2108TrialBalanceDefinitionImport.xlsx;扩展属性=“Excel 12.0 XML; HDR = NO”

我大部分时间如何解决 我转到任务管理器enter image description here

重新启动应用服务器

因为它只发生在舞台和制作环境中。如果我备份数据库并在DEV或QA中工作则没有问题。重启服务只能起作用;尽管如此,服务的内存消耗并未过载,它只消耗了大约30-35%的内存。 请让我知道您可能有任何想法我会非常感激。 谢谢。

与错误消息一起

SISServiceBiz.RunPackage调用:package name = WorkbookDefinitionsImport.dtsx错误:数据处理器失败。错误消息:检查工作表错误:超出系统资源。堆栈跟踪:在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接)    在System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningObject)    在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionOptions userOptions)    在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions userOptions)    在System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)    在System.Data.OleDb.OleDbConnection.Open()

0 个答案:

没有答案