Application creates files on the client not the server

Posted on 2006-11-16
Last Modified: 2010-04-16
Hello experts:

I've inherited a C# Windows application that when it runs on a server (win 2000), it works like a charm.
During the run it creates some text files on the server drive. These files are used at the end of the run to do a bulk insert into sql.

But when I run it from a client it outputs the text files not on the server drive but on the client's drive so the application has an exception during the bulk insert because it's looking for the text files on the server drive.

Has anybody heard of this and if so what I can do so that when I run the application from the client, it outputs the text files(needed for the bulkinsert) into the server drive not the clients's.

Question by:lancerxe
  • 7
  • 5

Author Comment

ID: 17961337
The path is defined at the @Application.StartupPath

Author Comment

ID: 17961450
If the @Application.StartupPath gets the path for the executable file that started the application, then that's why the text files are outputted on the server drive if the application is run from the server and are outputted on the client's drive when the application is run from the client.

How can I output the text files on the server drive when the application is run from the client's.?
I guess Application.StartupPath does not help me in this case.
LVL 22

Accepted Solution

cookre earned 500 total points
ID: 17961534
Create two path variables, one for files to reside locally, and one for files to reside on the server, say, LocalPath and ServerPath.

During program initialization, set them both to the local path, say, StartupPath, then check to see if you're running on a server or workstation.  If the former, reset ServerPath to the appropriate UNC or with a drive mapping, if one exists.
LVL 22

Expert Comment

ID: 17961550
Oops, that's 'latter', not 'former'.

Author Comment

ID: 17961575
Thanks cookre but I have a question.
Is there a way to determine from inside the code whether aplication is running on a server or workstation?

Author Comment

ID: 17961760
I found this VB6 code that may help me determine whether aplication is running on a server or workstation.
Am I on the right track ?

Private Declare Function GetSystemMetrics Lib "user32" (ByVal
nIndex As Long) As Long

Function IsTerminalServicesSession() As Boolean
   Dim b As Boolean

   b = GetSystemMetrics(SM_REMOTESESSION)

   IsTerminalServicesSession = b
End Function


    If (IsTerminalServicesSession()) Then
        ' It's a Terminal Server session
        ' It's local on the user's workstation
    End If

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

LVL 22

Expert Comment

ID: 17961779
Now, why did I suspect that was coming?

This usually depends on the organization's infrastructure.

Is there a distinguishing characteristic in computer names?

Do workstations get their IPAs via DHCP and servers static?

Do workstations/servers have services/agents that servers/workstations don't (for example W3SVC (IIS))?

If there are sufficiently few servers, one can check against the actual names (poor form).

Can they be distinguished by OS version?

Can they be distinguished by drive mappings, or lack thereof?
LVL 22

Expert Comment

ID: 17961786
If every time it's run on a server is via a Terminal Services session, then yes.

Author Comment

ID: 17965052
Thanks cookre.
I get the idea.

Author Comment

ID: 17979940
Hello cookre:

We are almost there.

Here's what i did.

1) I use  drive mapping to acces the server path. (y:\)
2) Modified the code to output to server path  (y:\) if running from the client.
3) It works because the History.txt files is now created on the server (mapped drive y:\).

However during the BulkInsert step, I get this error:
Error [42000] [MS Sql Server Driver] [Sql server] Could not bulk insert because file y:\History.txt could not be opened. OS System error 3(system cannot find the path specified)

The error says the path cannot be found. But how come it found the path when History.txt was created on the mapped drivey:\.
Could this be a right issue?

LVL 22

Expert Comment

ID: 17980505
I'd guess it's just a normal file not found problem.

Alas, I don't know enough about MSSQL to give a good diagnosis, but a guess might be that the mapping to y was done on one box, a path containing y: was then passed to and executed on another box - that doesn't know what y: is.

If that's the case, passing a UNC would get around the problem.

Author Comment

ID: 17980518
As I suspected it was a rights issue.
Everything is working  

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now