By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

File copy from Remote machine probelm

P: n/a
Hi everybody,

I have problem in copying file from DatabaseServer to WebServer.Both
machines are on LAN.

Let me explain in details what i am doing & wht i want to achieve...

I am using sqlserver 2000 & asp.net 2005 for my project..

I have written one stored procedure which creates one Text file on
database server.. & i want to copy that file in virtual path of my
project on webserver..

I am using following statement to copy a file..

strTextFileName = "E:\DestinationReportText\"
File.Copy(ConfigurationManager.AppSettings("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

When i debug code on webserver then everything works well, but when i
run this code from IIS on same machine then it gives following
Error ..
/************************************************** ***********
Server Error in '/www' Application.
--------------------------------------------------------------------------------

Logon failure: unknown user name or bad password.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.IO.IOException: Logon failure: unknown user
name or bad password.
************************************************** *********/

and to solve this I have given Full permission for "Report_Text"
folder to admin user, to anonymous user, & tried other lots of
stuffs,, but cound not make it to work...

is any one have idea on this ?
Jan 5 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you must give permission on the remote machine... to the user that the iis
is running (IUSR)

Exemple:
IIS HOST - MACHINE NAME - IISHOST
FILE HOST - MACHINE NAME - FILEHOST
You must giver permission in the folder on the FILEHOST to
IISHOST\IUSR_IISHOST
"Bhavesh" <bh*********@gmail.comwrote in message
news:0d**********************************@d4g2000p rg.googlegroups.com...
Hi everybody,

I have problem in copying file from DatabaseServer to WebServer.Both
machines are on LAN.

Let me explain in details what i am doing & wht i want to achieve...

I am using sqlserver 2000 & asp.net 2005 for my project..

I have written one stored procedure which creates one Text file on
database server.. & i want to copy that file in virtual path of my
project on webserver..

I am using following statement to copy a file..

strTextFileName = "E:\DestinationReportText\"
File.Copy(ConfigurationManager.AppSettings("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

When i debug code on webserver then everything works well, but when i
run this code from IIS on same machine then it gives following
Error ..
/************************************************** ***********
Server Error in '/www' Application.
--------------------------------------------------------------------------------

Logon failure: unknown user name or bad password.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.IO.IOException: Logon failure: unknown user
name or bad password.
************************************************** *********/

and to solve this I have given Full permission for "Report_Text"
folder to admin user, to anonymous user, & tried other lots of
stuffs,, but cound not make it to work...

is any one have idea on this ?

Jan 6 '08 #2

P: n/a

Here is the code you can use to access shared file with given
username/password
//used in calling WNetAddConnection2
[StructLayout(LayoutKind.Sequential)]
public struct NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
[MarshalAs(UnmanagedType.LPStr)]
public string lpLocalName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpRemoteName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpComment;
[MarshalAs(UnmanagedType.LPStr)]
public string lpProvider;
}
//WIN32API - WNetAddConnection2
[DllImport("mpr.dll",
CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int WNetAddConnection2A(
[MarshalAs(UnmanagedType.LPArray)] NETRESOURCE[] lpNetResource,
[MarshalAs(UnmanagedType.LPStr)] string lpPassword,
[MarshalAs(UnmanagedType.LPStr)] string lpUserName,
int dwFlags);
[DllImport("mpr.dll",
CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int WNetCancelConnection2A(
[MarshalAs(UnmanagedType.LPStr)] string lpName,
int dwFlags, int fForce);

private byte[] GetFSMSFile(string sFile)
{
NETRESOURCE[] nr = new NETRESOURCE[1];
nr[0].lpRemoteName = "\\SHAREDSERVER\FOLDER";
nr[0].lpLocalName = ""; //mLocalName;
nr[0].dwType = 1; //disk
nr[0].dwDisplayType = 0;
nr[0].dwScope = 0;
nr[0].dwUsage = 0;
nr[0].lpComment = "";
nr[0].lpProvider = "";
int iErr = WNetAddConnection2A(nr,UserPassword, ShareUser, 0);
if (iErr 0)
throw new Exception("Can not connect to shared folder");
FileStream st = null;
try
{
st = new FileStream("\\SHAREDSERVER\FOLDER\myfile.txt",
FileMode.Open);
int iLen = (int)st.Length;
byte []b = new byte[iLen];
st.Read(b, 0, iLen);
return b;
}
finally
{
if( st != null )
st.Close();
WNetCancelConnection2A(_sFSMSShare, 0, -1);
}
}
"Bhavesh" <bh*********@gmail.comwrote in message
news:0d**********************************@d4g2000p rg.googlegroups.com...
Hi everybody,

I have problem in copying file from DatabaseServer to WebServer.Both
machines are on LAN.

Let me explain in details what i am doing & wht i want to achieve...

I am using sqlserver 2000 & asp.net 2005 for my project..

I have written one stored procedure which creates one Text file on
database server.. & i want to copy that file in virtual path of my
project on webserver..

I am using following statement to copy a file..

strTextFileName = "E:\DestinationReportText\"
File.Copy(ConfigurationManager.AppSettings("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

When i debug code on webserver then everything works well, but when i
run this code from IIS on same machine then it gives following
Error ..
/************************************************** ***********
Server Error in '/www' Application.
--------------------------------------------------------------------------------

Logon failure: unknown user name or bad password.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.IO.IOException: Logon failure: unknown user
name or bad password.
************************************************** *********/

and to solve this I have given Full permission for "Report_Text"
folder to admin user, to anonymous user, & tried other lots of
stuffs,, but cound not make it to work...

is any one have idea on this ?

Jan 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.