none
IO Exception " The device is not ready"

    Question

  • I have developed a vb.net application which creates a csv file from database. When I run it from my system it works perfectly but when I copy the files from release folder to a folder on the server and runs the .exe file it give me IO Exception error. “The device is not ready”

     

    Private Sub CreateCustomersCSV()

     

    ********** Access to database through ODBC is working fine*********

     

       Dim fs As String = filename = "filename" & mydate & ".csv"

       Console.WriteLine(filename)         ******* prints the filename at this point

        Dim csvFile As String = "D:\Scripts\Accounts\" & filename

        If File.Exists("D:\Scripts\Accounts\" & filename) Then

           'shows message if csvFile of same name exist

           MsgBox("File Exist")

        End If

                '****************

        Dim fs As New FileStream(csvFile, FileMode.Create, FileAccess.Write)

        Dim s As New StreamWriter(fs)

            s.BaseStream.Seek(0, SeekOrigin.End)

            s.WriteLine("field1, field2, field3, field4")

            s.Close()

     MsgBox("file Created")

    End Sub

     

     

    I have installed Dot Net framework 4.0 on the server because I am using visual studio 2010.

     

    Any help will be appreciated.

     

    thanks

    • Moved by Andrew.Wu Thursday, January 20, 2011 10:22 AM (From:.NET Framework Setup)
    Tuesday, January 18, 2011 6:22 PM

Answers

  • The first question to ask is if your server has a D:\, or if the D:\ is pointed to a CD drive. Further, you could make your code a little more efficient by change the File.Exits() line to use the variable you created above it rather than typing it in again incase you do need to change the path.

    The "The device is not ready" is usually caused by pointing to a CD drive that has no CD in it. Also, if you can avoid it, try to not hard-code paths into your code.

     

    Modified Code:

    Private Sub CreateCustomersCSV()
     
    ********** Access to database through ODBC is working fine*********
     
      Dim fs As String = filename = "filename" & mydate & ".csv"
      Console.WriteLine(filename)     ******* prints the filename at this point
      Dim csvFile As String = "D:\Scripts\Accounts\" & filename
      If File.Exists(csvFile) Then
        'shows message if csvFile of same name exist
        MsgBox("File Exist")
      End If
          '****************
      Dim fs As New FileStream(csvFile, FileMode.Create, FileAccess.Write)
      Dim s As New StreamWriter(fs)
        s.BaseStream.Seek(0, SeekOrigin.End)
        s.WriteLine("field1, field2, field3, field4")
        s.Close()
     MsgBox("file Created")
    End Sub
    

    • Proposed as answer by dave92082 Wednesday, January 19, 2011 12:04 AM
    • Marked as answer by Kee PoppyModerator Tuesday, January 25, 2011 12:36 PM
    Wednesday, January 19, 2011 12:03 AM
  • In that case you must determine if the drive is_ready which seems letter D: points to your optical drive (guess).

    So, you can use DriveInfo.IsReady function like that:

    Dim drive As New IO.DriveInfo("D:")
            If drive.IsReady Then
                ' Do something when the drive is ready
               ' Put the code in your post here

            End If

     

    Hope this helps,


    Saygılarımla, Onur Güzel

    Yazgeliştir Forumları'ndayım.

    Microsoft Haber Grupları Profilim (VB.NET)

    • Proposed as answer by Onur Güzel Saturday, January 22, 2011 11:18 PM
    • Marked as answer by Kee PoppyModerator Tuesday, January 25, 2011 12:36 PM
    Saturday, January 22, 2011 11:17 PM

All replies

  • The first question to ask is if your server has a D:\, or if the D:\ is pointed to a CD drive. Further, you could make your code a little more efficient by change the File.Exits() line to use the variable you created above it rather than typing it in again incase you do need to change the path.

    The "The device is not ready" is usually caused by pointing to a CD drive that has no CD in it. Also, if you can avoid it, try to not hard-code paths into your code.

     

    Modified Code:

    Private Sub CreateCustomersCSV()
     
    ********** Access to database through ODBC is working fine*********
     
      Dim fs As String = filename = "filename" & mydate & ".csv"
      Console.WriteLine(filename)     ******* prints the filename at this point
      Dim csvFile As String = "D:\Scripts\Accounts\" & filename
      If File.Exists(csvFile) Then
        'shows message if csvFile of same name exist
        MsgBox("File Exist")
      End If
          '****************
      Dim fs As New FileStream(csvFile, FileMode.Create, FileAccess.Write)
      Dim s As New StreamWriter(fs)
        s.BaseStream.Seek(0, SeekOrigin.End)
        s.WriteLine("field1, field2, field3, field4")
        s.Close()
     MsgBox("file Created")
    End Sub
    

    • Proposed as answer by dave92082 Wednesday, January 19, 2011 12:04 AM
    • Marked as answer by Kee PoppyModerator Tuesday, January 25, 2011 12:36 PM
    Wednesday, January 19, 2011 12:03 AM
  • In that case you must determine if the drive is_ready which seems letter D: points to your optical drive (guess).

    So, you can use DriveInfo.IsReady function like that:

    Dim drive As New IO.DriveInfo("D:")
            If drive.IsReady Then
                ' Do something when the drive is ready
               ' Put the code in your post here

            End If

     

    Hope this helps,


    Saygılarımla, Onur Güzel

    Yazgeliştir Forumları'ndayım.

    Microsoft Haber Grupları Profilim (VB.NET)

    • Proposed as answer by Onur Güzel Saturday, January 22, 2011 11:18 PM
    • Marked as answer by Kee PoppyModerator Tuesday, January 25, 2011 12:36 PM
    Saturday, January 22, 2011 11:17 PM