This forum is meant for questions and discussions about the X# language and tools
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Fri Oct 05, 2018 4:24 pm
Hello,
I'm trying to build a connection string like this:
Code: Select all
String.Format( "Driver={Microsoft access Driver (*.mdb)};Dbq={0};Uid=Admin;Pwd=;", cDatabase )
But it gives a runtime error because of the parentheses { and }.
Is there any possibility to mask them?
TIA
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580 Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany
Post
by FFF » Fri Oct 05, 2018 4:37 pm
Wolfgang,
FUNCTION Start() AS VOID
LOCAL c AS STRING
c:="Driver={Microsoft access Driver (*.mdb)};Dbq={0};Uid=Admin;Pwd=;"
Console.WriteLine(c)
RETURN
works for me.
Seems i miss the point
EDIT Obviously.
BTW, there should be a "Delete" button for own posts...
Adding an "i" wouldn't be of use?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Fri Oct 05, 2018 4:44 pm
Hi Karl,
if you add a String.Format() and a parameter, it fails.
The same is occurring when using the prefix "i".
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
robert
Posts: 4518 Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands
Post
by robert » Fri Oct 05, 2018 5:44 pm
Wolfgang, you can escape the { and } characters by adding two of them in a row, so you will have to write:
"Driver={{Microsoft access Driver (*.mdb)}};Dbq={0};Uid=Admin;Pwd=;"
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Fri Oct 05, 2018 6:07 pm
Hi Robert,
thank you very much! This works.
Thank you again.
Wolfgang
P.S. this is used in a X# monitoring service that will go into production on Monday
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Jamal
Posts: 315 Joined: Mon Jul 03, 2017 7:02 pm
Post
by Jamal » Fri Oct 05, 2018 7:13 pm
I don't know about X#, but in C# whenever you want certain characters like in a string, I used the @ sign prefix.
For example: @"programs filestest"
otherwise I have to write @"program filestest"
Jamal
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Fri Oct 05, 2018 7:36 pm
Hi Jamal,
normally this works also in X# (but with the prefix 'e' instead of '@'), but this does no worked for the '{' character.
The answer from Robert helped, doubling the '{' and the '}' character solved the problem.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Chris
Posts: 4902 Joined: Thu Oct 08, 2015 7:48 am
Location: Greece
Post
by Chris » Fri Oct 05, 2018 10:09 pm
Hi Jamal,
In X#, it's the opposite of c#. c# uses escaped strings by default and you need to use @ in order to make them "regular" strings. In X#, literal strings are "regular" by default, and you need to prefix them with e to make them escaped.
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu