问题
For example:
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="\\na1b\uj\UP647529\Year 2\Managing Data and Security\Employee.accdb";
Visual studio won't let me run my program until I remove the spaces but thats where the database is..
How can I sort out that connection string to make Visual studio happy?
回答1:
It looks more like the problem is with the quotation marks in the string literal.
Try replacing each quote with two sets:
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""\\na1b\uj\UP647529\Year 2\Managing Data and Security\Employee.accdb""";
Alternatively, you can ditch the literal and use escape characters:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"\\\\na1b\\uj\\UP647529\\Year 2\\Managing Data and Security\\Employee.accdb\"";
With all those backslashes in the file path, though, it can be a little hard to read.
来源:https://stackoverflow.com/questions/20241862/what-to-do-about-spaces-on-my-connection-string