How to fix index was outside the bounds of the array in SQL Server

Microsoft SQL Server 2017 Reporting Services - 14.0.600.1763 (x64)
Microsoft SQL Server 2017 - Database Server - 14.0.3421.10 (x64)


Index was outside the bounds of the array.

RSPortal!reportserverwebapp!RSPortal.exe!3d!12/01/2021-21:06:18:: e ERROR: OData exception occurred: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: An unexpected error occurred in Report Processing. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.at Microsoft.ReportingServices.Library.ReportingService2005Impl.SetReportDefinition(String Report, Byte[] Definition, Guid batchId, Warning[]& Warnings)at Microsoft.ReportingServices.Library.ReportingService2005Impl.SetReportDefinition(String Report, Byte[] Definition, Warning[]& Warnings)at Microsoft.ReportingServices.Library.ReportingService2010Impl.SetItemDefinition(String ItemPath, Byte[] Definition, String expectedItemTypeName, Property[] Properties, Warning[]& Warnings)at Microsoft.ReportingServices.WebServer.ReportingService2010.SetItemDefinition(String ItemPath, Byte[] Definition, Property[] Properties, Warning[]& Warnings)at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)at Microsoft.SqlServer.ReportingServices2010.ReportingService2010.SetItemDefinition(String ItemPath, Byte[] Definition, Property[] Properties)at Microsoft.SqlServer.ReportingServices2010.RSConnection2010.SoapMethodWrapper`1.ExecuteMethod(Boolean setConnectionProtocol)at Microsoft.SqlServer.ReportingServices2010.RSConnection2010.SetItemDefinition(String itemPath, Byte[] definition, Property[] properties)at Microsoft.ReportingServices.Portal.Services.SoapProxy.SoapAuthenticationHelper.ExecuteWithWindowsAuth[TReturn](SoapHttpClientProtocol soapClient, IPrincipal userPrincipal, Func`1 func)at Microsoft.ReportingServices.Portal.Repositories.CatalogItemRepository.UpdateReport(IPrincipal userPrincipal, String origItemPath, Report item, Boolean renameOrMove, String[] delta)at Microsoft.ReportingServices.Portal.Repositories.CatalogItemRepository.Update(IPrincipal userPrincipal, String origItemPath, CatalogItem catalogItem, String[] delta)at Microsoft.ReportingServices.Portal.ODataWebApi.V2.Controllers.CatalogItemsController.PutEntity(String key, CatalogItem entity)at Microsoft.ReportingServices.Portal.ODataWebApi.Controllers.Reflection.EntitySetReflectionODataController`1.Put(ODataPath oDataPath, T value)at lambda_method(Closure , Object , Object[] )at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

--- End of stack trace from previous location where exception was thrown ---


From what I can tell, SSRS does not like the IF statements when I try to upload the report from a Report Builder session.

Need assistance with converting IF block/blocks to CASE statements:

declare @startDate as datetime

declare @endDate as datetime

declare @currentMonth int

select @currentMonth = datepart(mm, getdate())

--Show the current last week for the month.if @wkStartDate is null and @wkEndDate is nullbeginif @currentMonth = @monthNamebeginselect @startDate = DATEADD(wk, 0, DATEADD(wk, DATEDIFF(wk, 0,getdate()), -2))select @endDate = dateadd(dd, 6, @startDate)end--Show the last week of the month that was choosen.if @currentMonth <> @monthNamebeginselect @endDate = max(TheDate) from hlxlookup.dbo.Lookup_date_calendar where datepart(yyyy, TheDate) = @year AND DATEPART(mm, TheDate) = @monthNameselect @startDate = TheDate from hlxlookup.dbo.Lookup_date_calendar where TheDate < @endDate and TheDayOfWeek = 7end

end

elsebeginselect @startDate = @wkStartDateselect @endDate = @wkEndDate

end

This was an interesting error which I received while trying to uninstall SQL Server.  In this blog, we would learn how to fix error Index was outside the bounds of the array, which might come during uninstallation of SQL Server.

I must say this was an unfortunate situation where my machine got crashed while SQL Server install was in progress. To get rid of the “incomplete” installation, I decided to remove it and install it again. I went to add/remove program and selected “uninstall” for SQL Server 2017 as I was welcomed by error – Index was outside the bounds of the array. I looked into Summary.txt file and found below.

Overall summary:
Final result: Failed: see details below
Exit code (Decimal): -2146233080
Exit facility code: 19
Exit error code: 5384
Exit message: Index was outside the bounds of the array.
Requested action: Uninstall

Further, I could see below in the same log.

How to fix index was outside the bounds of the array in SQL Server

This was the exception

Exception type: System.IndexOutOfRangeException
Message: Index was outside the bounds of the array.
HResult : 0x80131508
Stack:
at Microsoft.SqlServer.Configuration.InstallWizard.InstanceSelectionController.SaveData()
at Microsoft.SqlServer.Configuration.InstallWizardFramework.InstallWizardPageHost.PageLeaving(PageChangeReason reason)
at Microsoft.SqlServer.Configuration.WizardFramework.UIHost.set_SelectedPageIndex(Int32 value)
at Microsoft.SqlServer.Configuration.WizardFramework.NavigationButtons.nextButton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Detail.txt also showed similar information

(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to open registry subkey Software\Microsoft\Microsoft SQL Server\Instance Names
(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to open registry subkey SQL
(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to get registry value
(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to open registry subkey OLAP
(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to get registry value
(06) 2018-11-25 09:48:24 Slp: Sco: Attempting to open registry subkey RS
(06) 2018-11-25 09:48:24 Slp: No installed instance features found for InstanceName = ”
(06) 2018-11-25 09:48:24 Slp: Final InstallID = ‘cba7cce5-c24c-463d-8608-08fc78c8e678’
(06) 2018-11-25 09:48:24 Slp: End calculate InstallID
(01) 2018-11-25 09:48:27 Slp: Error: Action “Microsoft.SqlServer.Configuration.UIExtension.WaypointAction” threw an exception during execution.

WORKAROUND/SOLUTION

It was clear from the log that installation didn’t reach to the stage where it has to be configured. That’s why we are seeing <UNCONFIGURED> for the instance name.

Instead of UI, I decided to use the command line to install. So, I went to below folder.

C:\Program Files\Microsoft SQL Server\140\Setup Bootstrap\SQL2017

And use below the line in command prompt.

SETUP.EXE /ACTION=UNINTSALL

This time, I was able to get to the UI and choose “<UNCONFIGURED>” instance

How to fix index was outside the bounds of the array in SQL Server

… and remove SQL successfully.  

I was unable to find out this trick on the internet. Hopefully, this would help someone who needs it.

Reference: Pinal Dave (https://blog.sqlauthority.com)