Hi,
Not sure if my question belongs in an ASP.NET or MSSQL forum..
I have an ASP.NET webpage built in VS2010 with an Input field with the functionality to browse to a network directory, select a text file, read content and upload the data to an MSSQL database table. Nothing fancy.
I am programming on a client, debugging, and running the website locally and the process works like a charm. When I publish the site to a webserver, browse to it and do exactly the same thing the following server error it thrown:
_________________________________________________________________________________________
Server Error in '/' Application.
Could not find a part of the path 'Z:\Data\AQVD_ReadReport20101108020000.txt'.
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.DirectoryNotFoundException: Could not find a part of the path 'Z:\Data\AQVD_ReadReport20101108020000.txt'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path 'Z:\Data\AQVD_ReadReport20101108020000.txt'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +224
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +1142
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +82
System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) +87
System.IO.StreamReader..ctor(String path) +30
MeteringInnovation._Default1.UploadFileButton_Click(Object sender, EventArgs e) in Z:\Visual Studio Projects\MeteringInnovation\MeteringInnovation\Arqiva\Default.aspx.vb:8
System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +118
System.Web.UI.HtmlControls.HtmlInputButton.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
_________________________________________________________________________________________
VB code:
Imports System.IO
Imports System.Data.SqlClient
Public Class _Default1
Inherits System.Web.UI.Page
Private Sub UploadFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UploadFile.ServerClick
Dim sr As New StreamReader(File1.Value)
Dim strLine As String = ""
Do Until sr.EndOfStream
strLine = sr.ReadLine
saveData(strLine)
Loop
UploadResultLabel.Text = "Data imported"
End Sub
Private Sub saveData(ByVal data As String)
Dim sb As System.Text.StringBuilder
Dim dc As New SqlConnection("Data Source=SERVER;Initial Catalog=DATABASE;Integrated Security=True")
Dim cm As New SqlCommand()
Dim dataValues() As String = data.Split(",")
Dim radioUnit As Long = dataValues(4)
Dim Meter As String = dataValues(5)
Dim dateTimeStamp As String = ""
Dim reading As Integer = 0
cm.Connection = dc
dc.Open()
For i As Integer = 14 To dataValues.Length - 1 Step 3
sb = New System.Text.StringBuilder
dateTimeStamp = dataValues(i)
reading = dataValues(i + 2)
sb.Append("Insert into dbo.TABLE Table (COL1, COL2, COL3, COL4) Values(")
sb.Append(COL1 & ",")
sb.Append("'" & COL2 & "',")
sb.Append("'" & COL3 & "',")
sb.Append(COL4 & ")")
cm.CommandText = sb.ToString()
cm.ExecuteNonQuery()
Next
dc.Close()
End Sub
This is in a domain Intranet environment, no firewalls etc. As I said, I am not sure if the problem is programming, network permissions or SQLdb permissions. Because of the nature of the error I'm swayed to think (as some forum posts suggest) ASPNET permissions are required on the sources directory. However, as these are networked I cannot check this option. IIS application pools are not a strong point for me, the site is in the default pool running v4.0 Integrated with NetworkService identity.
All pointers welcome.
Thanks