What can I do with white space in the connection string?

Bob Vu 0 Reputation points
2025-07-10T14:15:11.6133333+00:00

I wrote a small application in VB.NET (VS 2022), and it worked well with the connection string without white space. When I put it in the folder with spaces and that is where I have issues with it. How do I solve this issue with the white space?

I do not have issues with the following connection string

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\Project\mydb.mdb"

I do have issues with the following connection string

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Work\Project\mydb.mdb"

I tried with single quote around the directory path but it did not work

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Program Files\Work\Project\mydb.mdb'"

This is where the database will be. How do I solve this issue with the white space?

Developer technologies | VB
{count} votes

4 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 80,091 Reputation points Volunteer Moderator
    2025-07-10T17:35:54.76+00:00

    you need to use double quotes. so the string should be:

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Program Files\Work\Project\mydb.mdb";

    or as a c# literal:

    var cs = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Program Files\Work\Project\mydb.mdb"";";
    
    0 comments No comments

  2. Bob Vu 0 Reputation points
    2025-07-10T17:57:27.53+00:00

    Bruce,

    Thank you very much for answering my question.

    I did. I put it in double quote for entire connection string, but it did not work.

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Work\Project\mydb.mdb"

    That did not work. I then tried with the single quote around the directory path with double quote in place of the entire connection string and that did not work either.

    I should mention that this is VB.NET

    0 comments No comments

  3. Bob Vu 0 Reputation points
    2025-07-10T18:02:36.76+00:00

    Viorel,

    Thank you. I just tried it, and it did not work.

    I have been looking at Microsoft website this morning and could not find anything regarding to white space in connection string.


  4. Bob Vu 0 Reputation points
    2025-07-11T14:24:04.1466667+00:00

    Hello,

    Does anyone know how to solve the issues with the white space in connection string?

    Thanks.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.