Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET UNC connection string in C# 1

Status
Not open for further replies.

drepp

Programmer
Jan 29, 2003
7
US
I'm working on a C# ASP.NET app, and I'm having a problem with a connection string to an Access database. All of the examples I can find online se either server.mappath or the physical drive letter. However, all I have to work with in this case is a UNC path. What should the syntax for the connection string look like?

I tried "DATA Source=\\server\\dir\\dir\\file.mdb" but it keeps trying to resolve that down to "c:\server\dir\dir\file.mdb" as if the server was a directory!

So, please help! :) How do I get a UNC path to work as a data source path? I can do this in VB with "\\server\dir\dir\file.mdb", but I can't seem to figure out the similar code for C#.
 
You need to use [tt]"\\\\"[/tt] to get 2 backslashes, so it would be:
[tt]"DATA Source=\\\\server\\dir\\dir\\file.mdb"[/tt]
 
That worked! Thank you SO much! You wouldn't believe how hard it was to get that simple little piece of information.
 
drepp -

The slash character is an escape character in C# (and C, and C++). For instance, if you want to include a newline character, you'd concatenate '/n' (as a character) or "/n" (as a string) to your string. To have something equivalent to VB's vbCrLf constant, you'd concatenate "/n/r", which is newline and carriage return.

There is no equivalent to the VB.NET ControlChars module that has CrLf, NewLine, Tab, FormFeed, etc in it, although you could define a static class that had the same info if you like. Most C# programmers are happy with the escape characters, though.

Chip H.
 
Need to be careful about that. It's the backslash character "\" that acts as the escape character.
 
If you use @ infront of a string, then the / will not work as a escape character.

So this line "DATA Source=\\\\server\\dir\\dir\\file.mdb"
could look like this:
@"DATA Source=\\server\dir\dir\file.mdb"

Markus
 
rosenk -

Thanks for the reminder. I switch between systems (Win, Linux) a lot, so I always forget which is which.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top