user3041656
user3041656

Reputation: 61

What to do about spaces on my connection string?

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?

Upvotes: 1

Views: 4859

Answers (1)

valverij
valverij

Reputation: 4941

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.

Upvotes: 3

Related Questions