Results 1 to 8 of 8

Thread: Semicolon in Connection String

  1. #1

    Thread Starter
    Addicted Member Davor Geci's Avatar
    Join Date
    Sep 2009
    Posts
    224

    Semicolon in Connection String

    Hello,

    I have a problem, in my connection string in the password I have a semicolon and can't change the password.
    Do you have any idea how to solve it?

    Here is the connection string:

    Code:
    DRIVER={MariaDB ODBC 3.1 Driver};Port=3306;SERVER=test2.myserver.com;DATABASE=lpuxpbbo_test2;USER=lpuxpbbo_test2;PASSWORD=G;-GvE$aaAe];OPTION=11;
    Thanks for any suggestions,

    Davor
    My projects:
    Virtual Forms
    VBA Telemetry

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Semicolon in Connection String

    This works for user test with password test;123

    Dim cn As ADODB.Connection

    Set cn = New ADODB.Connection
    cn.Open "Provider=SQLOLEDB;Data Source=UCSDB;User ID=test;Password=""test;123"""

    cheers,
    </wqw>

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Semicolon in Connection String

    You can also use apostrophes as string delimiters in a connection string.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Semicolon in Connection String

    Quote Originally Posted by dilettante View Post
    You can also use apostrophes as string delimiters in a connection string.
    This

    cn.Open "Provider=SQLOLEDB;Data Source=UCSDB;User ID=test;Password='test;123'"

    bombs out with

    Format of the initialization string does not conform to the OLE DB specification.

    so it turns out single quotes cannot be used to escape semicolons inside values because single quotes can be used to escape double quotes inside value only.

    Edit: Reading again the quoted reply I'm not sure what "string delimiters" actually means.

    cheers,
    </wqw>

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Semicolon in Connection String

    You must have something else going on. I use apostrophe delimiters in connection strings all the time. This is especially common in Jet 4.0's Extended Properties strings which typically contain semicolons.

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Semicolon in Connection String

    Quote Originally Posted by dilettante View Post
    You must have something else going on.
    As OP stated what's going on -- there is a value with a semicolon which breaks OLEDB connect string parsing if not quoted as far as I understand the original problem.

    I just confirmed that such value cannot be quoted with single quotes. When value contains semicolon it *must* be quoted with double quotes. Other values (not containing semicolon) might be able to be quoted with single quotes.

    Another caveat is that ODBC vs OLEDB vs .Net connect string quoting differs. ODBC allows braces ({ and }) to be used for quoting too it seems reading the docs (not tested).

    cheers,
    </wqw>

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Semicolon in Connection String

    Nonsense.

    I use connection strings like that all the time without incident. OLEDB handles them just fine:

    Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Text;CSVDelimited=True;Hdr=True';Data Source='.'

    ODBC isn't involved in ADO connections, it is being invoked indirectly via OLEDB through the ODBC shim Provider MSDASQL, which is often left implied and thus defaulted.

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Semicolon in Connection String

    This one

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Text;CSVDelimited=True;Hdr=True';Data Source='test;123'"

    . . . and this one

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Text;CSVDelimited=True;Hdr=True';Data Source='.';Password='test;123'"

    . . . bomb out with "Format of the initialization string does not conform to the OLE DB specification."

    I'll let you figure out on yourself how to pass a folder or a password with a semicolon in the connect string. (Hint: single quotes don't work.)

    cheers,
    </wqw>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width