none
C# Connection String syntax error? RRS feed

  • Question

  • How to write it correctly? I think it is Excel 2013.

    Thanks.


    • Edited by VA_er Thursday, March 28, 2019 2:30 AM
    Thursday, March 28, 2019 2:29 AM

All replies

  • I don't know about connection strings, but I think your problem is that you need to either prefix the internal quote marks with backslashes, or prefix the whole string with an '@' sign and use pairs of quotes.

             string s1 = "A string with \"Quotes\" inside it.";
             string s2 = @"Another string with ""quotes"" inside it.";
    


    Thursday, March 28, 2019 3:06 AM
  • Hi 

    Thank you for posting here.

    For your question, you want to solve Connection String syntax error.

    You could try the following code.

    string path = "D:\\test.xlsx";
    string cononstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;MAXSCANROWS=0'";
    OleDbConnection oleDb = new OleDbConnection(cononstr);

    If you want to know more about OledbConnection string, you could refer to the following link.

    https://social.msdn.microsoft.com/Forums/en-US/e5f8ba13-21a3-4365-8651-25b6ae2ce267/reading-xlsx-files-from-oledb-provider?forum=adodotnetdataproviders

     

    Best regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    Thursday, March 28, 2019 8:31 AM
    Moderator
  • Hi 

    Thank you for posting here.

    For your question, you want to solve Connection String syntax error.

    You could try the following code.

    string path = "D:\\test.xlsx";
    string cononstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;MAXSCANROWS=0'";
    OleDbConnection oleDb = new OleDbConnection(cononstr);

    If you want to know more about OledbConnection string, you could refer to the following link.

    https://social.msdn.microsoft.com/Forums/en-US/e5f8ba13-21a3-4365-8651-25b6ae2ce267/reading-xlsx-files-from-oledb-provider?forum=adodotnetdataproviders

     

    Best regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    So you can use single quote for Properties ? I search online and it shows double quote, then I end up with TWO double quote at the end: one for Properties, the other for Provider. I guess that causes confusion.
    Thursday, March 28, 2019 12:09 PM
  • Hi

    Thanks for the feedback.

    Yes, I can use the single quote for Properties. I want to confirm if your problem has been solved. If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue. If not, please feel free to let me know.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, March 29, 2019 3:15 AM
    Moderator