NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Escape char translation causing failure in database open step

I have a step in my sequence that attempts to open an Access database with the following connection string:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileGlobals.ServerPath & FileGlobals.DNX1UPath & "Databases\\MTAS_Data.mdb;Persist Security Info=False"
 
where the following globals are defined:
FileGlobals.ServerPath = \\\\Ift\\EngProjects\\MnfgTest\\
FileGlobals.DNX1UPath = TMS\\Working TPS\\Access Gateways\\DNX1U\\
 
Therefore, the data source will evaluate to the following:
 
Every backslash is doubled because I'm using the escape sequence "\\" to represent backslash - I initially didn't do this, and just about everything that referenced the path failed.  The trouble is, the open database step now fails saying the path is invalid.  Which is true according to what it claims is the data source:
\\\Ift\EngProjects\MnfgTest\TMS\Working TPS\Access Gateways\DNX1U\Databases\MTAS_Data.mdb
(Note that the initial 4 backslashes have been translated to 3 backslashes...  This is a departure from elsewhere in the code, where TestStand correctly interprets it as 2 backslashes.)
 
My preference is to stay with this mechanism for specifying the database (as opposed to defining a data link), but I'm not sure what the appropriate way to specify a double backslash so that it will always be interpreted correctly.  Any suggestions would be greatly appreciated.
0 Kudos
Message 1 of 3
(3,217 Views)

Hi Rob,

You are on the right path. If you typed the the string directly into the Connection String, it would need to be typed with the escape characters, as such:

 
However, since you are using variables, the escaping is done automatically for you. So, you can type in:
 
 
The DB driver apparently accounts for the double slashes; however, it does not account for the quadruple slashes, which is why you are seeing the error message with 3 slashes.
 
So, I would recommend that you remove the double slashes from your variables and try it out.
 
Regards,
 
Matt M.
NI
0 Kudos
Message 2 of 3
(3,188 Views)

Thanks for the response, Matt.  I was able to get this to work by stripping off the first two backslashes using the Right() method.  It still seems strange to me that the message displayed three backslashes at the beginning...  If the variable automatically dealt with the escape sequences, and then the DB properly handles double-backslash escapes as well, I'd think that it may still fail, but due to a single backslash - not a triple backslash.  Ah well...  It works.  🙂

0 Kudos
Message 3 of 3
(3,184 Views)