Decrease Font Size
Increase Font Size
   BLOG

Format of the initialization string does not conform to specification starting at index 51.

Format of the initialization string does not conform to specification starting at index 51.

I was running the code from http://www.aspsnippets.com/post/2009/01/31/Export-Data-To-Excel-using-ADONet.aspx

String strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source=C:\test\book1.xls;" + "Extended Properties='Excel 8.0;HDR=Yes'";

OleDbConnection connExcel = new OleDbConnection(strExcelConn);

and get the following error.

Format of the initialization string does not conformto specification starting at index 51.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 51.

 

Then I notice that the problem is from "C:\test\book1.xls;" because of the "\", so, in order to get rid of that error message, all we have to do is include "@" in the string. With that being said, the new syntax of the strExcelConn will become:

String strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;"+ @"Data Source=C:\test\book1.xls;" + "Extended Properties='Excel 8.0;HDR=Yes'";