C# 通过SQL代理作业运行SSIS包
我擅长SSIS,我创建了一个包,可以将excel文件加载到SQL SERVER表中 我编写C#代码只提取第一张表的名称,然后包将加载第一张表中的数据(仅) 当我通过投标时,该软件包运行良好。但是当我通过SQL代理作业运行这个包时,同一个包在C代码步骤抛出错误 我看到很多帖子都认为这可能是因为在c代码中使用了C# 通过SQL代理作业运行SSIS包,c#,.net,sql-server,excel,ssis,C#,.net,Sql Server,Excel,Ssis,我擅长SSIS,我创建了一个包,可以将excel文件加载到SQL SERVER表中 我编写C#代码只提取第一张表的名称,然后包将加载第一张表中的数据(仅) 当我通过投标时,该软件包运行良好。但是当我通过SQL代理作业运行这个包时,同一个包在C代码步骤抛出错误 我看到很多帖子都认为这可能是因为在c代码中使用了Microsoft.interop.excel引用 在C#中是否有其他方法可以提取excel文件的第一个工作表名称(不基于升序),而不使用inter-op库 或者,在代码中使用inter-op
Microsoft.interop.excel
引用
在C#中是否有其他方法可以提取excel文件的第一个工作表名称(不基于升序),而不使用inter-op库
或者,在代码中使用inter-op时,如何配置SQL代理作业以成功运行
我的服务器是64位的
我尝试在“C:\Windows\System32\config\systemprofile”中创建“桌面”文件夹
错误:说明:System.Reflection.TargetInvocationException:
调用的目标已引发异常。-->
System.NullReferenceException:对象引用未设置为实例
指一个物体。在
ST_ecfa668f250a45e18c95639c9ffd64d4.csproj.ScriptMain.Main()---
内部异常堆栈跟踪的结束---at
System.RuntimeMethodHandle.\u InvokeMethodFast(对象目标,对象[])
参数、SignatureStruct&sig、MethodAttributes、MethodAttributes、,
RuntimeTypeHandle类型所有者)位于
System.RuntimeMethodHandle.InvokeMethodFast(对象目标,对象[])
参数、签名sig、MethodAttributes、MethodAttributes、,
RuntimeTypeHandle类型所有者)位于
System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags
invokeAttr,绑定器绑定器,对象[]参数,CultureInfo区域性,
布尔skipVisibilityChecks)在
System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags
invokeAttr,Binder Binder,对象[]参数,CultureInfo区域性)在System.RuntimeType.InvokeMember处(字符串名称,BindingFlags bindingFlags、绑定器绑定器、对象目标、对象[]提供的参数、, ParameterModifier[]修饰符,CultureInfo区域性,字符串[] namedParams),位于System.Type.InvokeMember(字符串名称,BindingFlags invokeAttr,绑定器绑定器,对象目标,对象[]参数,CultureInfo 文化)在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.vstatasksscriptingEngine.ExecuteScript() 结束错误:2015-02-27 11:24:00.23代码:0x00000001
来源:用户邮件描述: System.Reflection.TargetInvocationException:已引发异常 通过调用的目标。--> System.Data.SqlClient.SqlException:与网络相关或 建立到的连接时发生特定于实例的错误 SQL Server。找不到服务器或无法访问服务器。验证 实例名称正确且SQL Server配置为 允许远程连接。(提供程序:命名管道提供程序,错误:40)- 无法在上打开与SQL Server(SQL Server)的连接 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔断开连接)位于 System.Data.SqlClient.TdsParser.ThroweException和Warning(TdsParserStateObject stateObj)位于System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionDS connHandler,布尔值 IgnoresInOpenTimeout,Int64 TimerSpire,布尔加密,布尔 trustServerCert、布尔集成安全性、SqlConnection 拥有对象)位于 System.Data.SqlClient.sqlinternalconnectionds.AttemptOneLogin(ServerInfo serverInfo、字符串newPassword、布尔值IgnoresInOpenTimeout、Int64 TimerSpire,SqlConnection owningObject)位于 System.Data.SqlClient.sqlinternalconnectionds.loginnofilover(字符串 主机、字符串newPassword、布尔重定向EducserInstance、, SqlConnection owningObject、SqlConnectionString connectionOptions、, Int64 timerStart)在 System.Data.SqlClient.sqlinternalconnectionds.OpenLoginEnlist(SqlConnection owningObject、SqlConnectionString连接选项、字符串 新密码,布尔重定向EduseInstance)位于 System.Data.SqlClient.SqlInternalConnectionDS..ctor(DbConnectionPoolIdentity 标识、SqlConnectionString连接选项、对象提供程序信息、, 字符串newPassword,SqlConnection owningObject,布尔值 重定向导出(实例)在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项、对象池组ProviderInfo、数据库连接池池、, DbConnection owningConnection)位于 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection、DbConnectionPool池、DbConnectionOptions选项) 位于System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection 拥有…包执行fa…步骤失败 C代码-
您必须在32位计算机上运行BIDS,这就是包成功运行的原因。在您的UAT服务器上,请在SQL作业步骤中将包配置为以32位模式运行。为此,请修改配置SSIS包的SQL作业步骤- 1) 转到执行选项 2) 选中“使用32位运行时”对应的复选框
它应该可以解决您的问题。尝试创建此文件夹:
C:\Windows\SysWOW64\config\systemprofile\Desktop
目标是拥有一个SQL作业SSIS包,其中包含C3脚本,可在网络共享上动态创建excel文件。我能够使用代理帐户从SQL Server直接从SSIDB运行包。但是,无法作为作业运行。最后,在经历了长时间的挫折之后。感谢下面的链接。我非常小心地在UAT服务器(64位)中执行SSIS包。我还尝试通过BIDS在UAT服务器中执行作业……工作正常……此外,如果我禁用脚本组件并在sql代理中运行该作业,那么也可以正常工作。它总是失败
using System;
using System.Data;
using System.Diagnostics;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
using Microsoft.Office.Interop;
using System.Runtime.InteropServices;
namespace ST_ecfa668f250a45e18c95639c9ffd64d4.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{ /*Passing the file path via User::File_Name Variable*/
string FileName = Dts.Variables["User::File_Name"].Value.ToString();
Microsoft.Office.Interop.Excel.Application xlApp = null;
Microsoft.Office.Interop.Excel.Workbook excelBook = null;
try
{
xlApp = new Microsoft.Office.Interop.Excel.Application();
excelBook = xlApp.Workbooks.Open(FileName, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
string[] excelSheets = new string[excelBook.Worksheets.Count];
int i = 0;
foreach (Microsoft.Office.Interop.Excel.Worksheet wSheet in excelBook.Worksheets)
{
excelSheets[i] = wSheet.Name;
i++;
}
Dts.Variables["User::WorkSheetName"].Value = excelSheets[0] + "$";
}
catch (Exception ex)
{
excelBook.Close(false, FileName, null);
Marshal.ReleaseComObject(excelBook);
string error = ex.Message;
}
finally
{
excelBook.Close(false, FileName, null);
Marshal.ReleaseComObject(excelBook);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}