In a nutshell this is due to an incompatibility between .NET and Windows. The most likely candidate for the cause would be an upgrade to either Windows or .NET. Overall, check the Windows and SQL Server patch levels. The CLR/.NET that is affected is Microsoft.SqlServer.Types.

To poke around to see what else might be at risk, issue these queries from master:

This is a handy script to cycle through every character in a column to determine what each ascii value is. This is especially useful when a string match isn't matching. Often times, there is a hidden space, etc.

SELECT
dbfile.name AS DatabaseFileName,
dbfile.size/128 AS FileSizeInMB,
sysFG.name AS FileGroupName,
dbfile.physical_name AS DatabaseFilePath
FROM
sys.database_files AS dbfile
INNER JOIN
sys.filegroups AS sysFG
ON
dbfile.data_space_id = sysFG.data_space_id

-- for a more general look by filegroup, try this:

with fileConfig as
(SELECT
dbfile.name AS DatabaseFileName,
(dbfile.size/128) AS FileSizeInMB,
sysFG.name AS FileGroupName,
dbfile.physical_name AS DatabaseFilePath
FROM
sys.database_files AS dbfile
INNER JOIN
sys.filegroups AS sysFG
ON
dbfile.data_space_id = sysFG.data_space_id
)
select FileGroupName,
sum(FileSizeInMB) as TotalFilegroupInMB
from fileConfig
group by FileGroupName
order by FileGroupName

There are probably open sessions on the database you are attempting to bring offline. SQL Server is trying to roll back any existing workloads in-flight for that database.

Issue the sp_who2 command from a new connection (master db) and view what's active. If you see activity, let it complete--or if you don't want the sessions to complete for whatever reason, issue the kill command for the spid(s).

If you are seeing the "connection refused" message when attempting to set up a localhost access port, the chances are good that the port is blocked from allowing connections through Windows. To open the port, follow these instructions:

1. Navigate to Control Panel, System and Security and Windows Firewall.2. Select Advanced settings and highlight Inbound Rules in the left pane.3. Right click Inbound Rules and select New Rule.4. Add the port you need to open and click Next.5. Add the protocol (TCP or UDP) and the port number into the next window and click Next.6. Select Allow the connection in the next window and hit Next.7. Select the network type as you see fit and click Next.8. Name the rule something meaningful and click Finish.

This sql script will start an agent job on a remote server. If you're running this as a step in another agent job, keep in mind that the job you are running it from will be determined to be successful, even if the remote job fails--as this is an asynchronous kick off only.