该进程无法访问文件'C:\Users\Aina Co\Desktop\Aina Backup\Aina Backup\bin\Debug\datastore.mdf',因为它正由另一个进程使用。 [英] The process cannot access the file 'C:\Users\Aina Co\Desktop\Aina Backup\Aina Backup\bin\Debug\datastore.mdf' because it is being used by another process.

查看:52
本文介绍了该进程无法访问文件'C:\Users\Aina Co\Desktop\Aina Backup\Aina Backup\bin\Debug\datastore.mdf',因为它正由另一个进程使用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码但无法关闭连接



cnnstr =数据源=。\SQLEXPRESS; AttachDbFilename =& CurDir()& \datastore.mdf; Integrated Security = True; Connect Timeout = 30; User Instance = True



im use this code but cant close connection

cnnstr = " Data Source=.\SQLEXPRESS;AttachDbFilename=" & CurDir() & "\datastore.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

Dim con As New SqlConnection(cnnstr())
       Dim com As New SqlCommand("insert into tblbackuphistory values('" & dateshamsi & "','" & saat & "','" & mas & "',N'" & user & "')", con)
       If con.State = ConnectionState.Closed Then
           con.Open()
       End If
       com.ExecuteNonQuery()
       com.Cancel()
       com.Connection.Close()
       con.Close()

       com.Connection.Dispose()
       con.Dispose()

推荐答案

请看我过去的回答:如何压缩错误'它已经被vb.net中的另一个进程'使用了 [ ^ ]。



< dd> -SA
Please see my past answer: how to compress the error 'it is already used by another process' in vb.net[^].

—SA


这样的东西可以解决问题:



Something like this will do the trick:

Dim con As New SqlConnection(cnnstr())
Using Dim com As New SqlCommand("insert into tblbackuphistory values('" & dateshamsi & "','" & saat & "','" & mas & "',N'" & user & "')", con)
Try
If con.State = ConnectionState.Closed Then
    con.Open()
End If
com.ExecuteNonQuery()
Finally
' More Stuff
End Try





使用将处置连接,您不需要这样做。



The Using will dispose of the connection, You don't need to do that.


这篇关于该进程无法访问文件'C:\Users\Aina Co\Desktop\Aina Backup\Aina Backup\bin\Debug\datastore.mdf',因为它正由另一个进程使用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆