none
Operating system error code 3(The system cannot find the path specified.).

    Question

  • I'm doing a bulk insert to a sql server and when I do so, the SQL server connection string I have is logged in as admin, but when I press the "submit" button I'm getting this error. The file that I'm trying to open is in a folder with admin read/write access and as I said the SQL connection string is for the admin account. I can also open the file from the SQL server. Anyone have any idea what causes this? The SQL server is SQL 2000 and the Web server is Windows Server 2003.

    Thank you,


    Doug

    • Moved by Tom PhillipsModerator Saturday, May 08, 2010 1:49 AM TSQL question (From:SQL Server Database Engine)
    Friday, May 07, 2010 4:50 PM

Answers

  • The file needs to be accessable on the server.  The file path is relative to the server, not your PC.  Also, if you are trying to use a share or a mapped drive it will not work.  You need to use the UNC path.
    Saturday, May 08, 2010 1:48 AM
    Moderator

All replies

  • Have you tried bcp program to do it from command line ?

    Where are you pressing submit button?

    Are you doing that on computer where both sql server and file exists?

    How you try to open the file?


    With kind regards
    Krystian Zieja
    http://www.projectnenvision.com
    Follow me on twitter
    My Blog
    Friday, May 07, 2010 5:32 PM
  • The file needs to be accessable on the server.  The file path is relative to the server, not your PC.  Also, if you are trying to use a share or a mapped drive it will not work.  You need to use the UNC path.
    Saturday, May 08, 2010 1:48 AM
    Moderator
  • Tom,

     

    I understand what you're saying and maybe I should have been clearer in my description. I have tried to open the file from the server and was able to. I am even able to edit/delete the file from the server, so it doesnt appear that it's a permissions issue. When you say use the UNC path, I've tried several different variations of the path and that didn't seem to work either. Maybe I'll have to reconfigure my path.

    Monday, May 10, 2010 2:48 PM
  • Ok so I have modified my asp.net code and I'm now getting this error:

    Could not find a part of the path

    So what may be causing this?

    Thank you,

    Doug

    Monday, May 10, 2010 4:29 PM
  • Please post the code you are trying to run.

    Also, the SQL Server service needs to be running as a "domain user", not "Local Service" to access domain resources.

    Tuesday, May 11, 2010 1:30 PM
    Moderator
  • Tom,

     

    I modified my machine.config on the server and resolved this issue. Evidently it was the username asp.net was using to open the command with. Now I'm getting this message:

     

    Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string ' )'. at System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQuer yTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at _Default.SaveToDatabase(String SavePath) in C:\Inetpub\wwwroot\Webfile1\Default.aspx.vb:line 78

     

    Imports System.IO
    Imports System.Data
    Imports System.Data.SqlClient
    Partial Class _Default
      Inherits System.Web.UI.Page
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
      End Sub
      Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click
        Dim SaveLocation As String = Server.MapPath("Data") & "\upload.txt'"
        If UploadFile(SaveLocation) Then
          'the file was uploaded: now try saving it to the database
          SaveToDatabase(SaveLocation)
        End If
      End Sub
      Private Function UploadFile(ByVal SavePath As String) As Boolean
        Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
    
        'Checking if the file upload control contains a file
        If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
          Try
            'checking if it was .txt file BEFORE UPLOADING IT!
            'You used to upload it first...but the file could be a virus
            If File1.FileName.EndsWith(".txt") = False Then
              'The file is not the expected type...do not upload it
              'just post the validation message
              message.Text = "Please submit a text file."
            Else
              'The file is a .txt file
              'checking to see if the file exists already
              'If it does exist Deleting the existing one so that the new one can be created
              If IO.File.Exists(SavePath) Then
                IO.File.Delete(SavePath)
              End If
    
              'Now upload the file (save it to your server)
              File1.PostedFile.SaveAs(SavePath)
    
              'After saving it check to see if it exists
              If File.Exists(SavePath) Then
                'Upload was sucessful
                message.Text = "Thank you for your submission"
                fileWasUploaded = True
              Else
                'the file was not saved
                message.Text = "Unable to save the file"
              End If
            End If
    
          Catch Exc As Exception
            'We encountered a problem
            message.Text = Exc.Message + " " + Exc.StackTrace
          End Try
        Else
          'No file was selected for uploading
          message.Text = "Please select a file to upload"
        End If
        Return fileWasUploaded
      End Function
    
      Private Sub SaveToDatabase(ByVal SavePath As String)
        Try
          ' and bulk import the data:  
          'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
          'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
          Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=sa;password=chili123;"
          Dim results As New DataTable
    
          Using con As New SqlConnection(connection)
            con.Open()
    
            ' execute the bulk import  
            Using cmd As SqlCommand = con.CreateCommand
    
              cmd.CommandText = "bulk insert dialerresults from '" & SavePath & "' " & _
              "with ( fieldterminator = ',', rowterminator = '\n' )"
    
              cmd.ExecuteNonQuery()
            End Using
          End Using
          'Else
          'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
          'End If
        Catch ex As Exception
          message.Text = ex.Message + ex.StackTrace
        End Try
      End Sub
    
    End Class
    
    The line in question is cmd.ExecuteNonQuery()
    I inserted a break point there and debugged the code and got the following information:
    Where it says "condition" that it says no condition and then at hit count it says break always (currently 0). 
    Tuesday, May 11, 2010 7:39 PM
  • Grab the exact CommandText, then go to SSMS and try this exact statement.
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Tuesday, May 11, 2010 7:51 PM
    Moderator