What to do about spaces on my connection string?

最后都变了- 提交于 2019-12-13 02:49:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!