none
出現"there is a file sharing violation..."之問題 RRS feed

  • 問題

  • 請教各位前輩與高手:

      我先在form1中新增資料庫及由 server中PULL資料到PDA,OK.

    登入成功後會將DBconnection.close()並且跳到form2,但是在form2中要再DBconnection.open()時卻出現上述ERROR,不知是否頁面切換時要注意什麼動作?

    2007年1月9日 上午 07:27

所有回覆

  • 看起來像是重覆連線的問題
    close後要切換時
    先檢查Connection.State是否為ConnectionState.Closed

    2007年1月9日 下午 03:49
  • 感謝Wu的回覆!

    不過我已經有判斷了!以下是我的程式

            Dim m_localDatabaseName As String = " \My Documents\localFastPos.sdf"
            Dim m_localDataSource As String = "Data Source =" & m_localDatabaseName
            Dim m_localConnection As SqlCeConnection = Nothing
            m_localConnection = New SqlCeConnection(m_localDataSource)
            Dim m_Prodid As String
            If m_localConnection.State = ConnectionState.Executing Then
                MessageBox.Show("The database is busy - try again!")
            End If

            If m_localConnection.State = ConnectionState.Closed Or m_localConnection.State = ConnectionState.Broken Then
                Try
                    m_localConnection.Close()
                Catch ex As SqlCeException
                    MessageBox.Show("1." & ex.Message)
                End Try
            End If


            '取得與資料庫的連線
            Dim cmd As System.Data.SqlServerCe.SqlCeCommand
            Dim selectData As String
            selectData = "select prodid,prodname from  localproduct where barcode='" & txtBarcode.Text & "'"
            Try
                m_localConnection.Open()   '<--------此處ERROR

                cmd = New SqlCeCommand(selectData, m_localConnection)
                Dim dr As SqlCeDataReader = cmd.ExecuteReader()
                While dr.Read
                    txtProductname.Text = dr(1)
                    m_Prodid = dr(0)
                End While
                dr.Close()
            Catch ex As SqlCeException
                Dim p As String = ex.Message
                MessageBox.Show("2:" & p)
            Finally
                If Not m_localConnection Is Nothing Then
                    m_localConnection.Close()
                End If
            End Try

    2007年1月11日 上午 12:36