finding drive letter

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
A customer installed my app (VB 2003) on his server. BUT when he tried to run it, it bombed because the data bases couldn't be found. I hard coded the drive in my app to "C:" and his server is lettered "E". ALSo when it comes time for his client PC's to mapped to his server to run the app, they too will bomb because they see his server as "P:"


Can anyone suggest some ideas on how to make my app see "relative" drives?

Thank you John M:(
 
Application.StartUpPath gives you the full path of where your exe is located
Environment.GetFolderPath() has a whole list of folder paths, most of which are based on the current user's profile too.
 
So as long as I have the database in one of the folders listed, example put it in Program Files, then the code would would allow the database to be seen regardless of the drive letter the PC on the network has its Program Files folder? I would create an Installer, then when the installer is run on the server, the database would be in the Program Files folder on the server drive "S" (as an example). Then when the networked PC's get mapped to the server to run the application, the code you suggested would "find" the database on the server drive "S" or whatever the server is actually lettered? Right?

I apolgized for the length of this, I am not experienced in .Net yet.

John
 
For the program to run on the server then yes, using one of those special folders would work, but if you're accessing on the server from another computer then you'd need to use the network path for the share to the folder, which wouldn't start with a drive letter, it'll start with a \\ServerName\ShareFolder

Luckily for you, connection strings allow network paths as well as local paths to work. What kind of database is it? If a network's involved my guess is SQL Server, Oracle or MySql.
 
The application uses Access data bases. There are small, most of them have less than 100 records. There are about 25 of them. There wouldn't be more than 15 students using it at the same time.

There is a way to capture the network path so that the application could be installed on other servers without hard-coding?

John M
 
Normally apps have settings being stored already, the network path would be one of them. This would allow them to change it later on without needing to get an updated exe (and dll's) from you
 
Do you mean that once the app runs OK on the server and that the networked pC is mapped to the shared folder on the server, there really isn't any need to adjust the code in the app for the networked PC's because as long as they are mapped to the SERVERNAME\SHAREDFOLDER it will find the databases?

John
 
Let's back up a minute, I'm confusing myself.

The app's on the server and the network share comes in where?
 
I apologized for the confusion. My little experience in getting apps to run on servers is the reason. I have listed my applicable code here. The app can find the databases when I run it locally. But when its installed on a server I was getting an error: "database not found". Since I had it hard coded to "C": I can see why (since the server drive was "E") Along with that issue I assume there would be a similar issue once the networked PC's are mapped to the server. They wouldn't see the databases either since they path was hard-coded as "C:".

You gave me some good leads on the server question making the drives relative. I was lost when it comes to the networked PC side. Does my code have to change also or just by mapping to the \\MyServer\MyShare resolved this relative drive issue?

Thank you for your time.

John M



Dim ConnString2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\NMPNMB2\BuyerValues.mdb;" & _
"User ID=Admin;" & _
"Password="

Dim cnn2 As OleDbConnection = New OleDbConnection(ConnString2)
Dim command2 As String = "INSERT INTO BuyerPicks " & _
"(StudentInitials, [StudentID], DayCare, [Bus], [Cable], Car, CarLeased, CarRepair, " & _
"Charity, Clothes, Electricity, Food, House, FoodRest, Appliances, SmallStuff, " & _
"Gas, Gifts, Heat, HotWater, InsApt, InsCar, InsCarIniPay, InsDen, InsHeal, InsHome, " & _
"InsLife, Internet, Laundry, LesiACT, LesiTH, PersCare, Phone, PhACT, PhPlan, Saving, Smoke, TaxExcise, TaxSales, Done, " & _
(
 
Ok, now that I'm seeing the overview here:
Your program running on the server would need to be using one of those special folders.
Your program running on other computers that connect the the server's share to connect to those databases would need to use the network path and not a special folder.

You can make your app work both ways by storing a string which is the path to where the databases are and just not use a special folder. The program should prompt for the path on first run (or when the path is blank, which it would be if the program hasnt been ran yet) or have the installer get it and write it to the settings file
 
I think I misled you. The goal is to install the app on the server. Then have all the networked pc's run the program from the server, so the app doesn't have to be installed on each pc. The app uses several small Access databases. The errors that occur when the app is installed on the server is that the "databases" can't be found. That's because I hard coded "C:" as the drive (it runs perfectly on a standalone pc's C: hard drive).

I really have 2 questions: (1) how can I code the app so that it can read the correct path to the databases while its on the server (any server really)
and (2) when the networked pc's run the app do I need to code it similarly like the code to correct the "can't find database" error on the server, or is it solved by just mapping the pc to the server?

I am trully sorry to have confused you.

John M
 
Back
Top