I am working with the Excel Interop namespace to change the connection string in Excel workbook connections.

Why, when I try to set the connection property ( MSDN OLEDBConnection.Connection ), does the error appear in the target line?
HRESULT exception: 0x800A03EC
application = new Application();
Workbook wb = application.Workbooks.Open(file.FullName);
Sheets wbs = wb.Worksheets;
IEnumerable<Workbook> workbooks = application.Workbooks.Cast<Workbook>();
foreach (var connection in wb.Connections.Cast<WorkbookConnection>()
.Where(c => c.Type == XlConnectionType.xlConnectionTypeOLEDB))
{
connection.OLEDBConnection.Connection = "Test Connection String";
}
application.Quit();
However, calling the Replace method, as shown below, works. I found this as a workaround, not knowing why Replace works in this case.
application = new Application();
Workbook wb = application.Workbooks.Open(file.FullName);
Sheets wbs = wb.Worksheets;
IEnumerable<Workbook> workbooks = application.Workbooks.Cast<Workbook>();
foreach (var connection in wb.Connections.Cast<WorkbookConnection>()
.Where(c => c.Type == XlConnectionType.xlConnectionTypeOLEDB))
{
var conString = connection.OLEDBConnection.Connection.ToString();
connection.OLEDBConnection.Connection =
conString.Replace("Test Connection String", "New Test Connection String");
}
application.Quit();
This is actually the only way I can change the connection string, so I ask what is the reason why set may cause an error.