I have a VB.Net program running on vista that says a file is in use but th开发者_StackOverflow社区e same program on XP does not have that error.
Make sure you wrap disposable resources in Using statement to ensure they are properly released:
Using conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=c:\BAAW\Data\BAAW.mdf;Integrated Security=True;User Instance=True")
Using cmd As conn.CreateCommand()
conn.Open()
cmd.CommandText = "SELECT * FROM Employees"
Using rdr As SqlDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine(rdr(0))
End While
End Using
End Using
End Using
Download Process Explorer - you can use that to determine which process has the file in question open.
精彩评论