I’m building a web service application that executes an SSIS package, but when I try to consume the service (published to IIS on localhost as Web Deploy - File System) I get this response (locally and from the outside):
System.NullReferenceException: Object reference not set to an instance of an object. at WebServiceApplication.CallSP.RunSSIS() in C:\Users\developers\source\repos\ajfmo\WebServiceApplication\WebServiceApplication\CallSP.asmx.cs: line 23
Which refers to this Line:
string connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
I've read all the other questions so in this case is not a duplicate.
This is my web.config setting for the connection.
<connectionStrings>
<clear />
<add name="DBConnection"
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=master;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
But when I'm debugging from VS it runs without any issue, Is it related to the IIS setup?.
Already tried (Using a Web Service or Remote Component to Run a Remote Package Programmatically) and got compilation errors - also don't understand the parameter that I need to pass.
This is my code right now.
[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();
}
}
}
I had use breakpoints and debugged in those lines, the result in the variable is Null, but if I hardcode the value or pass the string directly to the SqlConnection instance it also gives me System.NullReferenceException: Object reference not set to an instance of an object.
Please help.