Change connection string in MS Excel 2013 powerpivot

I am working on same solution where i need to update connection strings of multiple files in Bulk.But , Its working for MS Excel 2010 and not for Excel 2013.

Exception Result : "Exception from HRESULT: 0x800A03EC"
Code Snippet :

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook ppWorkbook = (Microsoft.Office.Interop.Excel.Workbook)xlApp.Workbooks.Open(fileNameBox.Text);
Microsoft.Office.Interop.Excel.Connections connections = ppWorkbook.Connections;

string newConnectionString = "Connection String";

try
{
foreach (Microsoft.Office.Interop.Excel.WorkbookConnection connection in connections)
{
connection.OLEDBConnection.Connection = newConnectionString;
}
}
catch (Exception ex)
{ }

It occurs while assigning the connection string to OLEDBConnection. Need solution for MS Excel 2013 c#.

0 answers