我正在构建一个执行SSIS包的Web服务应用程序,但是当我尝试使用该服务(作为Web Deploy-File System发布到localhost上的IIS)时,我得到了此响应(从本地和外部):] >
System.NullReferenceException:对象引用未设置为对象的实例。
在C:\ Users \ developers \ source \ repos \ ajfmo \ WebServiceApplication \ WebServiceApplication \ CallSP.asmx.cs中的WebServiceApplication.CallSP.RunSSIS()中:第23行引用此行:
。string connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
我已经阅读了所有其他问题,因此在本例中为非重复项
这是我的web.config设置。
<connectionStrings> <clear /> <add name="DBConnection" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=master;" providerName="System.Data.SqlClient"/> </connectionStrings>
但是当我从VS调试时,它可以正常运行,是否与IIS安装有关?。
已经尝试过(Using a Web Service or Remote Component to Run a Remote Package Programmatically)并出现编译错误-也无法理解我需要传递的参数。
这是我的代码。
[WebMethod] public string RunSSIS() { var connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { try { // Create the Integration Services object IntegrationServices integrationServices = new IntegrationServices(connection); // Get the Integration Services catalog Catalog catalog = integrationServices.Catalogs["SSISDB"]; // Get the folder CatalogFolder folder = catalog.Folders["SF2SQL"]; // Get the project ProjectInfo project = folder.Projects["SF2SQL"]; // Get the package PackageInfo package = project.Packages["Package.dtsx"]; // Run the package long executionIdentifier = package.Execute(false, null); // Checking completion status ExecutionOperation executionOperation = catalog.Executions[executionIdentifier]; while (!executionOperation.Completed) { System.Threading.Thread.Sleep(5000); System.Diagnostics.Debug.WriteLine("Running"); executionOperation.Refresh(); } if (executionOperation.Status == Operation.ServerOperationStatus.Success) { System.Diagnostics.Debug.WriteLine("Success"); return "Success"; } else if (executionOperation.Status == Operation.ServerOperationStatus.Failed) { System.Diagnostics.Debug.WriteLine("Failed"); return "Failed"; } else { System.Diagnostics.Debug.WriteLine("Something else…"); return "Something else…"; } } catch (SqlException e) { System.Diagnostics.Debug.WriteLine("SqlException: " + e.Message); return "Ooopss"; } finally { connection.Close(); } } }
我使用断点并在这些行中进行了调试,变量的结果为Null,但是如果我对值进行硬编码或将字符串直接传递给SqlConnection实例,它也会给我System.NullReferenceException:Object reference not set to对象的实例。
请帮助。 💔
我正在构建一个执行SSIS包的Web服务应用程序,但是当我尝试使用该服务(作为Web Deploy-File System发布到localhost上的IIS)时,我会收到此响应(本地和...
我刚解决了它,的确确实是在模拟在当前会话上下文中运行的应用程序时遇到的模拟问题,我仍然不确定为什么它没有检索或执行这些行,因为我以更简单的方式进行了一些测试查询并正常工作。
由于有了此答案How do you do Impersonation in .NET?,我才可以通过web.config使用模拟来解决问题