Resolve UNC Names
-
Hello, Directory.Exists(“\\localhost\c$”) and Directory.Exists(“\\localhost\SomeLocalShare”) and Directory.Exists(“\\127.0.0.1\c$”) and Directory.Exists(“\\127.0.0.1\SomeLocalShare”) all stop returning true once the network goes down. I know this seems obvious but how is it I can still resolve the local instance of SQL server? My question is how do I resolve a UNC name (assuming it is localhost) if the network is down, disabled, or non existent on Windows Xp pro and Better? I was thinking of a virtual port maybe or a virtual Nic. Any help will be very much appreciated Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
-
Hello, Directory.Exists(“\\localhost\c$”) and Directory.Exists(“\\localhost\SomeLocalShare”) and Directory.Exists(“\\127.0.0.1\c$”) and Directory.Exists(“\\127.0.0.1\SomeLocalShare”) all stop returning true once the network goes down. I know this seems obvious but how is it I can still resolve the local instance of SQL server? My question is how do I resolve a UNC name (assuming it is localhost) if the network is down, disabled, or non existent on Windows Xp pro and Better? I was thinking of a virtual port maybe or a virtual Nic. Any help will be very much appreciated Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
Okay, maybe this is really a silly question but why do you need to resolve a UNC to the localhost/local system? I'm trying to figure out what purpose this would serve and for the life of me I don't get it. Here's why I'm a bit lost: The localhost/local system is a known quantity and therefore you can write your code to use local system drive paths for accessing any information. Mike Poz
-
Okay, maybe this is really a silly question but why do you need to resolve a UNC to the localhost/local system? I'm trying to figure out what purpose this would serve and for the life of me I don't get it. Here's why I'm a bit lost: The localhost/local system is a known quantity and therefore you can write your code to use local system drive paths for accessing any information. Mike Poz
I’m writing a tablet app that has start up parameters in a Db. Some of the parameters are UNC paths to data libraries that may or may not be local. Some tables will have a constant connection to the LAN, others will be disconnected piroticly. I’ll know in advance the ones that are mobile and set the data stores to be local in the Db. I want to use the same logic in both connected and disconnected environments. (I’m able to assume that the app was started with either a connection to the Db or a copy of the data needed locally) Also how Universal is a naming convention if it Only works in a connected environment. In the real world 25 drives are not enough. I think the whole industry should do away with the idea of local letters and move completely to UNC \\Device\share\path. One idea I had was to find where windows holds its share info and find the local resource that way. In the db I’d have \\computerName\share so I could parse it out and compare to this list. In computer management Win still know what it is sharing even with no NIC Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
-
I’m writing a tablet app that has start up parameters in a Db. Some of the parameters are UNC paths to data libraries that may or may not be local. Some tables will have a constant connection to the LAN, others will be disconnected piroticly. I’ll know in advance the ones that are mobile and set the data stores to be local in the Db. I want to use the same logic in both connected and disconnected environments. (I’m able to assume that the app was started with either a connection to the Db or a copy of the data needed locally) Also how Universal is a naming convention if it Only works in a connected environment. In the real world 25 drives are not enough. I think the whole industry should do away with the idea of local letters and move completely to UNC \\Device\share\path. One idea I had was to find where windows holds its share info and find the local resource that way. In the db I’d have \\computerName\share so I could parse it out and compare to this list. In computer management Win still know what it is sharing even with no NIC Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
HahnTech wrote:
One idea I had was to find where windows holds its share info and find the local resource that way.
That's maintained in the registry under HKLM here: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares You'll find keys with each share name, and their data value contains permissions and local path to the share. This assumes your use account has the permissions to at least read this information.
HahnTech wrote:
I’ll know in advance the ones that are mobile and set the data stores to be local in the Db.
If you will know in advance what is local and what is remote, then it sounds to me like you need to have some error checking with some "if - else" blocks to deal with when your "directory.exists()" fails to return true. If(Directory.Exists(\\localhost\c$) { Connect(\\localhost\c$\datbase); } else { //try a possible local path using C:\ or //pop an error stating that the database is unavailable } Either way this is basically an error handling issue where you need to fail gracefully when your "directory.exists" returns false. Mike Poz
-
HahnTech wrote:
One idea I had was to find where windows holds its share info and find the local resource that way.
That's maintained in the registry under HKLM here: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares You'll find keys with each share name, and their data value contains permissions and local path to the share. This assumes your use account has the permissions to at least read this information.
HahnTech wrote:
I’ll know in advance the ones that are mobile and set the data stores to be local in the Db.
If you will know in advance what is local and what is remote, then it sounds to me like you need to have some error checking with some "if - else" blocks to deal with when your "directory.exists()" fails to return true. If(Directory.Exists(\\localhost\c$) { Connect(\\localhost\c$\datbase); } else { //try a possible local path using C:\ or //pop an error stating that the database is unavailable } Either way this is basically an error handling issue where you need to fail gracefully when your "directory.exists" returns false. Mike Poz
Thanks for the Reg Keys. I'll look into that solution. This is not an error handling problem. This is a windows problem with not Fully utilizing UNC. There is no way to convert the parts of a UNC name into a local path. A properly normalized db will have separate columns for device, share, and path (UNC: \\DeviceName\ShareName\Path) so its not as simply as If UNCpath exists Else just use local. That would require restructuring the Db. And as you probably know that’s not always an option. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net